Binary Expressions

2008-10-7

How To - Convert MySQL Timestamp/Datetime to Unix Timestamp

Filed under: — Adam @ 11:35 am

Background Knowledge


Since MySQL v4.1 timestamp and datetime data types are formatted “YYYY-MM-DD HH:MM:SS”. Prior to MySQL v4.1 the timestamp was formatted as YYYYMMDDHHMMSS” and datetime formatted as “YYYY-MM-DD HH:MM:SS”. Refer to MySQL Reference Manual for further details.

The Unix timestamp differs from MySQL. Unix’s timestamp is a integer value of seconds since January 1, 1970. For further explanation of Unix timestamps refer to Wikiepedia or UnixTimestamp.com.

Solutions


In MySQL you can use Unix_Timestamp() function.

Query Example: SELECT Unix_Timestamp(Date_Entered) FROM Foo;

Using PHP you can use strtotime() function.

PHP Example: $nUnixTimestamp = strtotime($nTimestamp);

Leave a Reply

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


25 queries. 0.360 seconds.
Copyright © 2004 - 2005 by Adam Douglas