UNIX_TIMESTAMP
PostgreSQL equivalent:
Returns Unix time, the number of seconds since 1970-01-01 00:00:00 UTC.
MySQL 8.4
UNIX_TIMESTAMP([date])- [ ]optional part
- date
- Date or datetime, the current moment by defaultDATETIMEOptional
Return value
An integer number of seconds, fractional if the date has fractional seconds; 0 for dates out of range, for example before 1970, and for a string not recognized as a date: UNIX_TIMESTAMP('abc') = 0
Examples
Current moment in seconds
MySQL 8.4
SELECT UNIX_TIMESTAMP();Payment dates in seconds
MySQL 8.4
SELECT payment_id,
date,
UNIX_TIMESTAMP(date) AS unix_time
FROM Payments;Date before 1970
MySQL 8.4
SELECT UNIX_TIMESTAMP('1969-12-31') AS unix_time;Details
A date without a time zone is treated as time in the session time zone (time_zone), so the result depends on the server settings.