Declaration
TOUNIXTIMESTAMP(datetime)
Description
This function converts a datetime expression datetime to a Unix timestamp (the number of seconds since '1970-01-01 00:00:00' UTC). If the parameter is of type DATE, the time part defaults to midnight (00:00:00).
Notice
This is a ClickHouse-compatible function. It is disabled by default and must be enabled by setting the sql_func_extension_mode parameter. For more information, see sql_func_extension_mode.
Examples
Enable the ClickHouse extension function mode.
obclient> ALTER SYSTEM SET sql_func_extension_mode = "ClickHouse";Returns an integer timestamp.
obclient> SELECT TOUNIXTIMESTAMP('2026-03-30 12:00:00');The return result is as follows:
+----------------------------------------+ | TOUNIXTIMESTAMP('2026-03-30 12:00:00') | +----------------------------------------+ | 1774843200 | +----------------------------------------+ 1 row in setReturns the Unix timestamp for 0:00 on the current day.
obclient> SELECT TOUNIXTIMESTAMP(DATE '2026-03-30');The return result is as follows:
+------------------------------------+ | TOUNIXTIMESTAMP(DATE '2026-03-30') | +------------------------------------+ | 1774800000 | +------------------------------------+ 1 row in set