The UNIX_TIMESTAMP() function returns a Unix timestamp or a calculated Unix time in seconds.
Withou an argument the function returns a Unix timestamp in seconds since '1970-01-01 00:00:00' UTC as an integer.
If UNIX_TIMESTAMP() is called with a "Date and Time" argument, the function returns the seconds since '1970-01-01 00:00:00' UTC of the argument.
The "Date and Time" argument can be of type DATE, DATETIME, TIMESTAMP or a number in the format YYMMDD or YYYYMMDD.
The SQL server interprets and converts "Date and Time" as a value in the current time zone.
If the "Date and Time" argument is NULL, the UNIX_TIMESTAMP() function returns NULL.
If the "Date and Time" argument is invalid, MariaDB returns NULL from version 5.3, while MySQL 8.0 returns 0 as the result.
It should be noted that the function calculates with a UTC date and the result of a "Date and Time" argument varies depending on the time zone. View example.
The inverse function of UNIX_TIMESTAMP() is the FROM_UNIXTIME() function. |