Conversion of MySQL Timestamp and DateTime to Unix based TimeStamp

About MySQL TimeStamp

* The Prior version of MySQL v4.1 the timestamp was formatted as like YYYYMMDDHHMMSS”
* since after MySQL v4.1 timestamp and datetime data types are formatted “YYYY-MM-DD HH:MM:SS”.

About Unix Based TimeStamp

* It is differ from MySQL. Unix’s timestamp is a integer value of seconds since January 1, 1970.


How To - Convert

(1) Using MySQL

* you can use Unix_Timestamp() function.
* Example:
SELECT Unix_Timestamp(Created) FROM CreatedItem;

(2) Using PHP
* you can use strtotime() function.
* Example:
$unixTimeStamp = strtotime($createdTimestamp);

No comments: