Declaration
FORMATDATETIME(date, format)
Description
This function formats a date or datetime expression date according to the specified format string and returns the formatted string. For example, FORMATDATETIME(date, '%Y-%m-%d %H:%i:%s').
Notice
This is a ClickHouse-compatible function. By default, it is not available. To use it, 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";Format the current date and time in the
YYYY-MM-DD HH:MI:SSformat.obclient> SELECT FORMATDATETIME(NOW(), '%Y year %m month %d day %H:%i:%s') AS formatted_date;The return result is as follows:
+---------------------------------+ | formatted_date | +---------------------------------+ | 2026-03-30 10:44:53 | +---------------------------------+ 1 row in set