PHP , formatting a TIMESTAMP retrieved from a mySQL db.

Al Neri

Diamond Member
Jan 12, 2002
5,680
1
81
i have $date pulled from a timestamp in MYSQL, how do i format it to show for example "9/16/2006 10:15 PM"
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
You might be able to use strtotime to convert $date into a Unix timestamp, which you can easily format using date().

Otherwise, you can use preg_match or substr to break up the MySQL timestamp into year, month, day, hour, minute and use mktime() to convert all of those values into a Unix timestamp.

date($format,strtotime($date));

date($format,mktime(.....));
 

Al Neri

Diamond Member
Jan 12, 2002
5,680
1
81
how do I subtract 5 from the hour (i believe its in GMT)

i think timestamp is in GMT?
 

Al Neri

Diamond Member
Jan 12, 2002
5,680
1
81
i took the unformatted datestamp and subtracted 50000 and it worked, will that always work?
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
yeah, i wouldn't subtract 5*3600 since it doesn't account for the leap day properly.