Name

UNIX_TIMESTAMP( )

Synopsis

UNIX_TIMESTAMP([datetime])

This function returns the number of seconds since the start of the Unix epoch (January 1, 1970, Greenwich Mean Time). Without a given time, this function will return the Unix time for the current date and time. Optionally, a date and time value (directly or by way of a column value) may be given for conversion to Unix time with this function.

SELECT UNIX_TIMESTAMP( )
          AS 'Now',
       UNIX_TIMESTAMP('2004-05-09 20:45:00')
          AS 'Same Time';
+----------------+----------------+
|           Now  |      Same Time |
+----------------+----------------+
|     1084153500 |     1084153500 |
+----------------+----------------+

The first column uses the function to determine the Unix time for the moment that the statement was entered. The second column uses the same function to determine the Unix time for the same date and time provided in a usual, readable format.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.