calendar was changed. For dates before 1582 (and possibly a later year in other locales), results from this function are not reliable. See Section 12.9, “What Calendar Is Used By MySQL?” , for details. 

Like TO_DAYS() , TO_SECONDS() , converts two-digit year values in dates to four-digit form using the rules in Section 11.2, “Date and Time Data Types” . 

In MySQL, the zero date is defined as ’0000-00-00’ , even though this date is itself considered invalid. This means that, for ’0000-00-00’  and ’0000-01-01’ , TO_SECONDS()  returns the values shown here: 

mysql> SELECT TO_SECONDS(’0000-00-00’); +--------------------------+ | TO_SECONDS(’0000-00-00’) | +--------------------------+ | NULL | +--------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> SHOW WARNINGS; +---------+------+----------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------+ | Warning | 1292 | Incorrect datetime value: ’0000-00-00’ | +---------+------+----------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT TO_SECONDS(’0000-01-01’); +--------------------------+ | TO_SECONDS(’0000-01-01’) | +--------------------------+ | 86400 | +--------------------------+ 1 row in set (0.00 sec) 

This is true whether or not the ALLOW_INVALID_DATES  SQL server mode is enabled. 

• UNIX_TIMESTAMP([ date ]) 

If UNIX_TIMESTAMP()  is called with no date  argument, it returns a Unix timestamp representing seconds since ’1970-01-01 00:00:00’  UTC. 

If UNIX_TIMESTAMP()  is called with a date  argument, it returns the value of the argument as seconds since ’1970-01-01 00:00:00’  UTC. The server interprets date  as a value in the session time zone and converts it to an internal Unix timestamp value in UTC. (Clients can set the session time zone as described in Section 5.1.15, “MySQL Server Time Zone Support” .) The date  argument may be a DATE , DATETIME , or TIMESTAMP  string, or a number in YYMMDD , YYMMDDhhmmss , YYYYMMDD , or YYYYMMDDhhmmss  format. If the argument includes a time part, it may optionally include a fractional seconds part. 

The return value is an integer if no argument is given or the argument does not include a fractional seconds part, or DECIMAL  if an argument is given that includes a fractional seconds part. 

When the date  argument is a TIMESTAMP  column, UNIX_TIMESTAMP()  returns the internal timestamp value directly, with no implicit “string-to-Unix-timestamp”  conversion. 

The valid range of argument values is the same as for the TIMESTAMP  data type: ’1970-01-01 00:00:01.000000’  UTC to ’2038-01-19 03:14:07.999999’  UTC. If you pass an out-of-range date to UNIX_TIMESTAMP() , it returns 0 . 

mysql> SELECT UNIX_TIMESTAMP(); 

