v.24.8Improvement

Functions formatDateTime and formatDateTimeInJodaSyntax Accept Optional Format Parameter

Functions formatDateTime and formatDateTimeInJodaSyntax now treat their format parameter as optional. If it is not specified, format strings %Y-%m-%d %H:%i:%s and yyyy-MM-dd HH:mm:ss are assumed. Example: SELECT parseDateTime('2021-01-04 23:12:34') now returns DateTime value 2021-01-04 23:12:34 (previously, this threw an exception). #67399 (Robert Schulze).
The functions formatDateTime and formatDateTimeInJodaSyntax now have an optional format parameter, defaulting to standard date-time formats when omitted.

Why it matters

This feature simplifies usage of formatDateTime and formatDateTimeInJodaSyntax by allowing calls without explicit format strings. It prevents exceptions caused by missing format arguments and provides sensible defaults, improving usability and reducing errors in common date-time parsing scenarios.

How to use it

Call formatDateTime or formatDateTimeInJodaSyntax without passing the format parameter. For example:

SELECT formatDateTime('2021-01-04 23:12:34')


This will parse and format the date-time using the default format %Y-%m-%d %H:%i:%s for formatDateTime and yyyy-MM-dd HH:mm:ss for formatDateTimeInJodaSyntax.