Skip to main content

Categories: Date/Time, System

UNIX_TIMESTAMP

Returns the Unix time representation of the input (DATE, TIMESTAMP, or timestamp string) or the current time if no input is provided. Unix time is the number of seconds since (or before) the Unix epoch (1970-01-01 00:00:00 UTC).

Syntax​

UNIX_TIMESTAMP() → int64​

Examples

UNIX_TIMESTAMP example
SELECT UNIX_TIMESTAMP()
-- 1624928208

UNIX_TIMESTAMP(date_timestamp_expression varchar) → int64​

  • date_timestamp_expression: The timestamp to convert to Unix timestamp. The expected format is YYYY-MM-DD HH24:MM:SS where HH can be a value 1-24.

Examples

UNIX_TIMESTAMP example
SELECT UNIX_TIMESTAMP('2021-12-22 13:44:11')
-- 1640180651

UNIX_TIMESTAMP(date_timestamp_expression varchar [, format varchar]) → int64​

  • date_timestamp_expression: The DATE or TIMESTAMP string to convert to Unix time.
  • format (optional): Specify the format of the time, date, or timestamp parameter, such as YY-MM-DD or HH:MM:SS.

Examples

UNIX_TIMESTAMP example
SELECT UNIX_TIMESTAMP('21-12-22', 'YY-MM-DD')
-- 1640131200
UNIX_TIMESTAMP example with a date format
SELECT UNIX_TIMESTAMP('03/15/2026', 'MM/DD/YYYY')
-- 1773532800
UNIX_TIMESTAMP example with a date and time format
SELECT UNIX_TIMESTAMP('03/15/2026 14:30:00', 'MM/DD/YYYY HH24:MI:SS')
-- 1773585000