unix_timestamp
Description
Syntax:
INT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(DATETIME date)
This function converts a DATE or DATETIME type to a UNIX timestamp.
If no parameters are input, the current time will be converted into a timestamp.
The parameter should be of DATE or DATETIME type.
If you input any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07, the function will return 0.
See date_format
for detailed introduction to formats.
The result may vary based on time zone.
Example
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1558589570 |
+------------------+
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30-19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30%3A19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('1969-01-01 00:00:00');
+---------------------------------------+
| unix_timestamp('1969-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
Keywords
UNIX_TIMESTAMP,UNIX,TIMESTAMP