v.24.8Improvement
Functions formatDateTime and formatDateTimeInJodaSyntax Accept Optional Format Parameter
FunctionsformatDateTimeandformatDateTimeInJodaSyntaxnow treat their format parameter as optional. If it is not specified, format strings%Y-%m-%d %H:%i:%sandyyyy-MM-dd HH:mm:ssare assumed. Example:SELECT parseDateTime('2021-01-04 23:12:34')now returns DateTime value2021-01-04 23:12:34(previously, this threw an exception). #67399 (Robert Schulze).
Why it matters
This feature simplifies usage offormatDateTime 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
CallformatDateTime 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.