PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Tue Aug 29, 2006 11:46 am
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.
Last edited by
tmaiden on Tue Aug 29, 2006 12:35 pm, edited 1 time in total.
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Tue Aug 29, 2006 12:24 pm
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
Last edited by
Oren on Tue Aug 29, 2006 12:30 pm, edited 2 times in total.
blackbeard
Forum Contributor
Posts: 123 Joined: Thu Aug 03, 2006 6:20 pm
Post
by blackbeard » Tue Aug 29, 2006 12:26 pm
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;
GM
Forum Contributor
Posts: 365 Joined: Wed Apr 26, 2006 4:19 am
Location: Italy
Post
by GM » Tue Aug 29, 2006 12:27 pm
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.
tmaiden
Forum Commoner
Posts: 64 Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:
Post
by tmaiden » Tue Aug 29, 2006 12:35 pm
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!