Considerations
This function was introduced in version V4.6.0.
Syntax
FORMATDATETIME(date, format)
Purpose
The FORMATDATETIME function takes a date or date-time expression date and a format string format and returns a string that represents date in the specified format. For example, FORMATDATETIME(date, '%Y-%m-%d %H:%i:%s').
Important
This function is compatible with ClickHouse. By default, it is not enabled. To enable it, you must set 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";Format the current date and time into the
YYYY-MM-DD HH:MI:SSformat.obclient> SELECT FORMATDATETIME(NOW(), '%Y-%m-%d %H:%i:%s') AS formatted_date;The return result is as follows:
+---------------------------------+ | formatted_date | +---------------------------------+ | March 30, 2026 10:44:53 | +---------------------------------+ 1 row in set
