FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Reformatting a DATETIME MySQL value after retrieving via PHP

 


Solugon
Currently, I'm taking the time and sending it to the database, then retrieving it and printing it onto the page, but I need a way to change the format of it from 0000-00-00 00:00:00 (year-month-day hour:minute:second) to something of the format "n/j/Y g:i a". Any idea how to do that?
hexkid
Solugon wrote:
Currently, I'm taking the time and sending it to the database, then retrieving it and printing it onto the page, but I need a way to change the format of it from 0000-00-00 00:00:00 (year-month-day hour:minute:second) to something of the format "n/j/Y g:i a". Any idea how to do that?


SQL
Code:
select unix_timestamp(date_column)

PHP
Code:
echo date('your format', $value_from_database);
Solugon
Ah, ok, thanks.
bladesage
Solugon wrote:
Ah, ok, thanks.


I'd suggest you change the fields containing the date to an INT(32) data type field. When inserting into the table, you can use the raw integer provided by the time() function. Then when you want to extract it from the database, you get back a timestamp, which can easily be formatted however you want it, using
Code:
date('n/j/Y g:i a', $date);

This assumes that the variable containing the database timestamp that you selected in the query is $date, change however you like.
Solugon
I just made a function to parse the DATETIME and reformat it. Laughing
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.