This is a discussion on Translating MySQL timestamp to datetime within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, Any thoughts on the easiest way to translate a MySQL timestamp (which looks like 20040422090941) to the datetime ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi All,
Any thoughts on the easiest way to translate a MySQL timestamp (which looks like 20040422090941) to the datetime format (which looks like 2004-04-22 09:09:41). This is just to make it easier for a human to read it. I have thought about splitting it into chunks using something like str_split, then piecing it back together, but it seems like there should be an easier way. And also, I am not running PHP5. I already tried date("Y-m-d H:i:s",strtotime("20040422090941")), and had no luck. strtotime cannot handle that format. This seems like the sort of thing you should be able to do in 1 line of code. Any pointers? -Josh |
|
|||
|
Joshua Beall wrote:
> Hi All, > > Any thoughts on the easiest way to translate a MySQL timestamp (which looks > like 20040422090941) to the datetime format (which looks like 2004-04-22 > 09:09:41). This is just to make it easier for a human to read it. > > I have thought about splitting it into chunks using something like > str_split, then piecing it back together, but it seems like there should be > an easier way. And also, I am not running PHP5. > > I already tried date("Y-m-d H:i:s",strtotime("20040422090941")), and had no > luck. strtotime cannot handle that format. > > This seems like the sort of thing you should be able to do in 1 line of > code. Any pointers? > > -Josh Select the date value from MySQL as a Unix timestamp eg. SELECT UNIX_TIMESTAMP(date) as date FROM table Then you can use the date() function on it with no problems. |