Note
This function is available starting from V4.6.0.
Syntax
TOUNIXTIMESTAMP(datetime)
Purpose
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 the DATE type, the time part is by default set to midnight (00:00:00).
Notice
This is a ClickHouse-compatible function. By default, it is not enabled. You must set the sql_func_extension_mode parameter to enable it. For more information, see sql_func_extension_mode.
Examples
Enable the ClickHouse extension function mode.
obclient> ALTER SYSTEM SET sql_func_extension_mode = "ClickHouse";Return 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 setReturn the Unix timestamp for midnight of 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
