Unix_timestamp (), Unix_timestamp (date)
If no parameter is called, returns a Unix timestamp (the number of seconds after the ' 1970-01-01 00:00:00 ' GMT) as an unsigned integer. If you call Unix_timestamp () with date, it returns the value of the parameter in the form of a number of seconds after the ' 1970-01-01 00:00:00 ' GMT. Date can be a date string, a DateTime string, a timestamp, or a number in the YYMMDD or YYYMMDD format of a local time.
Mysql> SELECT Unix_timestamp (); -882226357 mysql> SELECT unix_timestamp (' 1997-10-04 22:23:00 '); 875996580
When Unix_timestamp is used in the timestamp column, the function returns the internal timestamp value directly without any implied "string-to-unix-timestamp" conversions. If you pass an overflow date to Unix_timestamp (), it will return 0, but be aware that only the basic range check will be fulfilled (the year is from 1970 to 2037, the month is from 01 to 12, and the date is from 01 to 31).
Example of the conversion of timestamps and times under PHP:
PHP Code
$timestamp = 1210003200; $datetime = Date (' y-m-d h:i:s ', $timestamp); echo "The time stamp represents the time:", $datetime, "<br>\n"; echo "Back to timestamp from this time:", Strtotime ($datetime), "<br>\n";
Example of a time-stamp conversion under MySQL:
SQL Code
Select From_unixtime (1210003200) datetime, Unix_timestamp (From_unixtime (1210003200)) timestamp;