IMPORTANT: format-token translation here is BEST-EFFORT for a common
subset of tokens, NOT a full strftime-compatible formatting engine. Only
the following tokens are recognized in the input format string (case
sensitive, matched longest-first so e.g. HH24 is not partially consumed
by HH):
YYYY - 4-digit year
MM - 2-digit month (01-12)
DD - 2-digit day of month (01-31)
HH24 - 2-digit hour, 24-hour clock (00-23)
HH - 2-digit hour, 12-hour clock (01-12)
MI - 2-digit minute (00-59)
SS - 2-digit second (00-59)
Any other characters in format (literal separators like -, /, :,
spaces, etc) are passed through unchanged, best-effort, per dialect.
Dialect notes:
postgres/cockroachdb/redshift/oracle: TO_CHAR(expr, format) — these
tokens map onto TO_CHAR's native template natively, so the format string
passes through unchanged.
db2: VARCHAR_FORMAT(expr, format) (Db2's TO_CHAR-equivalent); tokens
pass through unchanged like Oracle/Postgres.
snowflake: TO_VARCHAR(expr, format); tokens pass through unchanged.
clickhouse: formatDateTime(expr, format), tokens translated to %Y,
%m, %d, %H, %I, %i, %S (ClickHouse's directives are
MySQL-strftime-like, notably using %i for minutes like MySQL).
Format a date/timestamp expression as a string.
IMPORTANT: format-token translation here is BEST-EFFORT for a common subset of tokens, NOT a full strftime-compatible formatting engine. Only the following tokens are recognized in the input
formatstring (case sensitive, matched longest-first so e.g.HH24is not partially consumed byHH):YYYY- 4-digit yearMM- 2-digit month (01-12)DD- 2-digit day of month (01-31)HH24- 2-digit hour, 24-hour clock (00-23)HH- 2-digit hour, 12-hour clock (01-12)MI- 2-digit minute (00-59)SS- 2-digit second (00-59) Any other characters informat(literal separators like-,/,:, spaces, etc) are passed through unchanged, best-effort, per dialect.Dialect notes:
TO_CHAR(expr, format)— these tokens map onto TO_CHAR's native template natively, so the format string passes through unchanged.DATE_FORMAT(expr, format), tokens translated to%Y,%m,%d,%H,%h,%i,%s.FORMAT(expr, format), tokens translated to .NET-styleyyyy,MM,dd,HH,hh,mm,ss.strftime(format, expr), tokens translated to%Y,%m,%d,%H,%I,%M,%S.VARCHAR_FORMAT(expr, format)(Db2's TO_CHAR-equivalent); tokens pass through unchanged like Oracle/Postgres.TO_VARCHAR(expr, format); tokens pass through unchanged.formatDateTime(expr, format), tokens translated to%Y,%m,%d,%H,%I,%i,%S(ClickHouse's directives are MySQL-strftime-like, notably using%ifor minutes like MySQL).