FORMAT_DATE and FORMAT_DATETIME turn DATE or DATETIME values into readable strings with custom patterns.
Formatted dates improve report readability, allow locale-specific displays, and support string concatenation in emails or exports.
Use FORMAT_DATE
for DATE
, FORMAT_DATETIME
for DATETIME
, and FORMAT_TIMESTAMP
for TIMESTAMP
.
Call FORMAT_DATE('%Y-%m', Orders.order_date)
. This returns values like 2024-06
.
Yes. FORMAT_DATE('%A, %d %B %Y', Orders.order_date)
outputs Saturday, 22 June 2024
.
%Y
=four-digit year, %m
=two-digit month, %d
=day, %A
=weekday name, %B
=month name.
Wrap the string with PARSE_DATE('%Y-%m-%d', string_col)
, then pass the result to FORMAT_DATE
.
Keep dates in native DATE/DATETIME types. Only format in the final SELECT to avoid breaking date math and filtering.
No. DATE has no timezone. For TIMESTAMP, FORMAT_TIMESTAMP uses the session time zone unless you supply one.
Yes. Set @@session.default_locale
or use SAFE_FORMAT_ functions with locale parameter.
Pattern tokens like %d and %m include leading zeros automatically (01-31, 01-12).