MySQL tutorial: UNIX_TIMESTAMP [EN]
top of page
CerebroSQL

MySQL: 

UNIX_TIMESTAMP

Syntax:
UNIX_TIMESTAMP([date])

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

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
https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html.) 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.

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.

When the date argument is a TIMESTAMP column, UNIX_TIMESTAMP() returns
the internal timestamp value directly, with no implicit
"string-to-Unix-timestamp" conversion.

The valid range of argument values is the same as for the TIMESTAMP
data type: '1970-01-01 00:00:01.000000' UTC to '2038-01-19
03:14:07.999999' UTC. If you pass an out-of-range date to
UNIX_TIMESTAMP(), it returns 0.

URL: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Example

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

bottom of page