Page 1 of 1

RESOLVED: MySQL DATETIME Format -> mm/dd/yyyy hh:mm:ss

Posted: Tue Aug 29, 2006 11:46 am
by tmaiden
I am having trouble converting...
2006-08-29 09:41:17 to 08/29/2006 09:41:17

This is what im already doing; yet it doesn't work

Code: Select all

date('m/d/y G:i:s', $row['timestamp'])
It yeilds, 12/31/69 17:33:26

Any help would be greatly appriciated.

Posted: Tue Aug 29, 2006 12:24 pm
by Oren
It must be a problem with your query, the PHP syntax is fine.

P.S I suggest that you format your date on the MySQL end.

Edit: Damn, I saw this: $row['timestamp'] and that's why I totally forgot it wasn't a timestamp at all :roll:

Posted: Tue Aug 29, 2006 12:26 pm
by blackbeard
You're not feeding it a timestamp, you need to convert it to one. Try this:

Code: Select all

$myTS = strtotime($row['timestamp']);
$myDate = date("m/d/Y G:i:s", $myTS;

echo $myDate;

Posted: Tue Aug 29, 2006 12:27 pm
by GM
In the query that extracts the timestamp do this:

Code: Select all

SELECT UNIX_TIMESTAMP(time_stamp) as time_stamp FROM table_name WHERE ... 
the PHP date function expects a unix timestamp (datatype long) as an input, not a datetime.

Posted: Tue Aug 29, 2006 12:35 pm
by tmaiden
I orginally did this:

Code: Select all

echo substr($row['timestamp'],5,2) . "/" . substr($row['timestamp'],8,2) . "/" . substr($row['timestamp'],0,4) . substr($row['timestamp'],10,9);
Then I used blackbeard's because it looks nicer.

Code: Select all

echo date("m/d/Y G:i:s", strtotime($row['timestamp']));
Thanks everyone.

RESOLVED!