timestamp converting into junk

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

Post Reply
jakeharlan
Forum Newbie
Posts: 1
Joined: Mon Mar 14, 2005 10:40 am
Location: Florida

timestamp converting into junk

Post 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 :(
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply