Translating MySQL timestamp to datetime

From: Joshua Beall (jbeall_at_donotspam.remove.me.heraldic.us)
Date: 04/22/04


Date: Thu, 22 Apr 2004 13:13:16 GMT

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



Relevant Pages

  • Translating MySQL timestamp to datetime
    ... 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 ... Any pointers? ...
    (alt.php)
  • Re: Translating MySQL timestamp to datetime
    ... "Joshua Beall" wrote in message ... > Any thoughts on the easiest way to translate a MySQL timestamp (which ... Any pointers? ...
    (comp.lang.php)