BigQuery · Date function
BigQuery FORMAT_DATE
FORMAT_DATE(format_string, date) turns a DATE into a STRING using % elements: FORMAT_DATE('%d/%m/%Y', d) gives 23/11/2026 and FORMAT_DATE('%B %Y', d) gives November 2026. Use it for labels, file names and display formats.
FORMAT_DATE prints a DATE in the layout you describe with format elements. The format string comes first and the date second, the reverse of most other databases.
The elements used most often, with the output for Monday, 2026-11-23: %Y 2026, %y 26, %m 11, %d 23, %e 23 (single-digit days padded with a space), %B November, %b Nov, %A Monday, %a Mon, %j 327 (day of year), %Q 4 (quarter), %u 1 (weekday, Monday = 1), %w 1 (weekday, Sunday = 0), %U 47 (Sunday-based week), %V 48 (ISO week), %G 2026 (ISO year), %F 2026-11-23, %x and %D 11/23/26. %% prints a percent sign. Names are always English.
Elements that need a time, such as %H, are not an error on a DATE: they are printed literally, so FORMAT_DATE('%H', d) returns the text %H. Use FORMAT_DATETIME or FORMAT_TIMESTAMP for times. To go the other way, from STRING to DATE, use PARSE_DATE with the same elements.
Syntax
FORMAT_DATE(format_string, date_expr)Arguments and return value
| Argument | Description |
|---|---|
format_string | A STRING of format elements and literal text, for example '%Y-%m-%d' or 'Week %V of %G'. |
date_expr | The DATE to format. NULL returns NULL. |
Returns: STRING
Examples
Common layouts
SELECT
FORMAT_DATE('%Y%m%d', DATE '2026-11-23') AS compact,
FORMAT_DATE('%d/%m/%Y', DATE '2026-11-23') AS european,
FORMAT_DATE('%B %d, %Y', DATE '2026-11-23') AS long_us,
FORMAT_DATE('%a %d %b', DATE '2026-11-23') AS short_label,
FORMAT_DATE('%Y-%m', DATE '2026-11-23') AS year_month;| compact | european | long_us | short_label | year_month |
|---|---|---|---|---|
| 20261123 | 23/11/2026 | November 23, 2026 | Mon 23 Nov | 2026-11 |
ISO week labels need %G, not %Y
December 29, 2025 belongs to ISO week 1 of 2026. Pairing %V with the calendar year %Y gives a label that points a year back.
SELECT
FORMAT_DATE('%G-W%V', DATE '2025-12-29') AS iso_label,
FORMAT_DATE('%Y-W%V', DATE '2025-12-29') AS wrong_label,
FORMAT_DATE('%G-W%V', DATE '2026-11-23') AS iso_label_nov;| iso_label | wrong_label | iso_label_nov |
|---|---|---|
| 2026-W01 | 2025-W01 | 2026-W48 |
Padding and numbering elements
SELECT
FORMAT_DATE('%d', DATE '2026-11-05') AS day_zero_padded,
FORMAT_DATE('[%e]', DATE '2026-11-05') AS day_space_padded,
FORMAT_DATE('%j', DATE '2026-11-23') AS day_of_year,
FORMAT_DATE('Q%Q %Y', DATE '2026-11-23') AS quarter_label;| day_zero_padded | day_space_padded | day_of_year | quarter_label |
|---|---|---|---|
| 05 | [ 5] | 327 | Q4 2026 |
Month labels that still sort correctly
Group and sort by the DATE, format only for display. Sorting by the label would put Apr before Feb.
WITH orders AS (
SELECT DATE '2026-01-14' AS order_date, 120 AS amount UNION ALL
SELECT DATE '2026-02-02', 50 UNION ALL
SELECT DATE '2026-04-30', 75
),
monthly AS (
SELECT DATE_TRUNC(order_date, MONTH) AS month, SUM(amount) AS revenue
FROM orders
GROUP BY month
)
SELECT FORMAT_DATE('%b %Y', month) AS month_label, revenue
FROM monthly
ORDER BY month;| month_label | revenue |
|---|---|
| Jan 2026 | 120 |
| Feb 2026 | 50 |
| Apr 2026 | 75 |
Common mistakes
- Swapping the arguments.
FORMAT_DATE(d, '%Y-%m-%d')has no matching signature; the format string comes first. - Porting
TO_CHAR(d, 'YYYY-MM-DD')from PostgreSQL, Oracle or Snowflake, orDATE_FORMATfrom MySQL. BigQuery uses % elements:FORMAT_DATE('%Y-%m-%d', d).CAST(d AS STRING FORMAT 'YYYY-MM-DD')accepts the Oracle-style model. - Using
%Mfor the month.%Mis minutes and%mis the month; on a DATE,%Mis printed as the literal text %M. - Sorting by the formatted string. 'Apr 2026' sorts before 'Feb 2026'. Keep the DATE for ORDER BY and GROUP BY.
- Combining
%Vwith%Y. ISO weeks need the ISO year%Gnear New Year.
Cost and performance
- FORMAT_DATE on a partitioning column in WHERE prevents partition pruning; BigQuery's pruning guide lists
FORMAT_DATE('%Y-%m-%d %H', ts)as a filter that scans everything. Compare the DATE column with a date range instead and format only in SELECT.
FAQ
How do I convert a date to a string in BigQuery?
CAST(d AS STRING) returns 2026-11-23. For any other layout use FORMAT_DATE, for example FORMAT_DATE('%d.%m.%Y', d).
How do I get the month name from a date?
FORMAT_DATE('%B', d) returns the full name, such as November, and FORMAT_DATE('%b', d) returns Nov. Names are English only.
How do I format a date as YYYYMMDD?
FORMAT_DATE('%Y%m%d', d) returns a STRING such as 20261123. Wrap it in CAST(... AS INT64) if you need a number.
Related
Errors you may hit
More date functions
All BigQuery date functions · All functions · BigQuery error messages
