UNIX_TIMESTAMP

UNIX_TIMESTAMP(date)

Returns the number of seconds since 1 January 1970 00:00:00 UTC. Without a parameter for the current moment, with a parameter for the given date – which is taken in the session time zone.

Parameters

  • date – optional, a DATE or DATETIME value. Without it, the current time.

Examples

The result depends on the session time zone – the examples run with the +01:00 time zone (Central European winter time):

SELECT UNIX_TIMESTAMP('2026-03-15 12:00:00') AS seconds, UNIX_TIMESTAMP('1970-01-01 01:00:00') AS epoch,
  UNIX_TIMESTAMP() > 1700000000 AS current_ts;
+------------+-------+------------+
| seconds    | epoch | current_ts |
+------------+-------+------------+
| 1773572400 |     0 |          1 |
+------------+-------+------------+

The same date in a different time zone gives a different number:

SET time_zone = '+00:00';
SELECT UNIX_TIMESTAMP('2026-03-15 12:00:00') AS in_utc;
+------------+
| in_utc     |
+------------+
| 1773576000 |
+------------+

Things to watch out for

  • The date is converted according to the session time zone (time_zone). When the time zones of the database and PHP differ, you get a shift of hours. The PHP functions time() and strtotime() work with UTC seconds.
  • The TIMESTAMP type and this function have an upper limit of 19 January 2038 in MySQL 8.0 and MariaDB 10.x (a 32-bit range) – a later date returns 0 or NULL. For dates after 2038, use DATETIME.

Related:
FROM_UNIXTIME()
NOW()