Page 1 of 1

timestamp converting into junk

Posted: Mon Mar 14, 2005 11:00 am
by jakeharlan
I figure this is probably a very noobie problem, but I haven't found the answer in my books or on php.net.

How do I convert a timestamp from a MySql database (type timestamp) into seconds since the Unix Epoch
I thought this would do the trick:
$myTime = 20050314000000;
$newTime = date('U', $myTime);

$newTime is coming out to some date in the year 2017...obviously not correct.

Please help :(

Posted: Mon Mar 14, 2005 11:16 am
by PrObLeM

Posted: Mon Mar 14, 2005 1:00 pm
by pickle
MySQL also has the ability to convert datetime (and probably date, and timestamp) column types to a unix timestamp:

Code: Select all

SELECT
  UNIX_TIMESTAMP(timestamp_field) as 'UNIX'
FROM
  example_table