ID EN
Date and Time Functions

UNIX_TIMESTAMP([date])

MySQL 8.4

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

Syntax

MYSQL
SELECT UNIX_TIMESTAMP();
1447431666
SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');
1447431619
SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');
1447431619.012

Examples

Example

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

MYSQL
SELECT UNIX_TIMESTAMP();
1447431666
SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');
1447431619
SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');
1447431619.012
Example 2

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.

MYSQL
SET time_zone = 'MET';
SELECT UNIX_TIMESTAMP('2005-03-27 03:00:00');
+---------------------------------------+
| UNIX_TIMESTAMP('2005-03-27 03:00:00') |
+---------------------------------------+
|                            1111885200 |
+---------------------------------------+
SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00');
+---------------------------------------+
| UNIX_TIMESTAMP('2005-03-27 02:00:00') |
+---------------------------------------+
|                            1111885200 |
+---------------------------------------+
SELECT FROM_UNIXTIME(1111885200);
+---------------------------+
| FROM_UNIXTIME(1111885200) |
+---------------------------+
| 2005-03-27 03:00:00       |
+---------------------------+