UNIX_TIMESTAMP( )

This MySQL function returns the number of seconds since the start of the Unix epoch (January 1, 1970, Greenwich Mean Time).

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

UNIX_TIMESTAMP([datetime])

Explanation

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 returns 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.

Examples

SELECT UNIX_TIMESTAMP( ) AS 'Now',
UNIX_TIMESTAMP('2008-05-09 20:45:00') AS 'Same Time from String';

+------------+-----------------------+
| Now        | Same Time from String |
+------------+-----------------------+
| 1210383900 |            1210383900 | 
+------------+-----------------------+

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 common, readable format.