How to convert string to DATE in BigQuery

Galaxy Glossary

How do I convert a string column to DATE in BigQuery?

PARSE_DATE or CAST turns text into DATE values for accurate filtering, grouping, and calculations.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

Why convert strings to DATE in BigQuery?

DATE columns sort, filter, and aggregate faster than text. Converting string timestamps lets you use date functions like DATE_DIFF, DATE_TRUNC, and partition pruning for cheaper, faster queries.

What syntax converts a string to DATE?

Use PARSE_DATE(format, string) when the text is not ISO-8601. Use CAST(string AS DATE) or DATE(string) when the text matches ISO-8601 (YYYY-MM-DD).

Which format patterns does PARSE_DATE accept?

BigQuery follows strftime patterns: %Y (4-digit year), %m (2-digit month), %d (2-digit day), etc. Combine them to mirror the incoming text exactly.

How do I pick the right approach?

ISO strings: CAST('2023-08-15' AS DATE). Non-ISO strings (e.g., 15/08/2023): PARSE_DATE('%d/%m/%Y', '15/08/2023'). Avoid PARSE_DATE on NULLs by wrapping with SAFE.PARSE_DATE.

Practical example: first order date per customer

Orders.order_date is VARCHAR '08/23/2023'. Convert then aggregate to find each customer’s first purchase date.

WITH converted AS (
SELECT customer_id,
PARSE_DATE('%m/%d/%Y', order_date) AS order_date
FROM `shop.Orders`
)
SELECT customer_id, MIN(order_date) AS first_order_date
FROM converted
GROUP BY customer_id;

Best practices for string-to-DATE conversion

1) Standardize input to ISO-8601 upstream if possible. 2) Use SAFE.PARSE_DATE to get NULL instead of errors. 3) Store dates as DATE, not STRING, to save cost and avoid repeated parsing.

Common mistakes and fixes

Mistake 1: Wrong format pattern causes "Failed to parse input". Fix by matching every literal and delimiter exactly.
Mistake 2: Direct CAST on non-ISO strings returns NULL. Use PARSE_DATE with the correct format or clean the data first.

Quick reference table

TaskRecommended FunctionISO string → DATECAST(col AS DATE)Non-ISO string → DATEPARSE_DATE(format, col)Skip errorsSAFE.PARSE_DATE(format, col)

Why How to convert string to DATE in BigQuery is important

How to convert string to DATE in BigQuery Example Usage


-- Compute monthly revenue when Orders.order_date is a string 'MM/DD/YYYY'
WITH clean AS (
  SELECT PARSE_DATE('%m/%d/%Y', order_date) AS order_dt,
         total_amount
  FROM `shop.Orders`
)
SELECT FORMAT_DATE('%Y-%m', order_dt) AS month,
       SUM(total_amount)          AS revenue
FROM clean
GROUP BY month
ORDER BY month;

How to convert string to DATE in BigQuery Syntax


-- ISO-8601 string
SELECT CAST('2023-09-02' AS DATE) AS iso_date;
-- shorthand
SELECT DATE('2023-09-02');

-- Non-ISO string with delimiter
SELECT PARSE_DATE('%d/%m/%Y', '02/09/2023') AS eu_date;

-- Ecommerce example: convert Orders.order_date then join
SELECT o.id,
       PARSE_DATE('%m/%d/%Y', o.order_date) AS order_date,
       c.name
FROM `shop.Orders` AS o
JOIN `shop.Customers` AS c ON c.id = o.customer_id;

Common Mistakes

Frequently Asked Questions (FAQs)

Can I suppress errors during conversion?

Yes. Wrap the function with SAFE.PARSE_DATE to return NULL instead of raising an error when parsing fails.

How do I handle date-time strings?

Use PARSE_TIMESTAMP for full timestamps, then extract the DATE: DATE(PARSE_TIMESTAMP(format, string)).

Does time zone affect PARSE_DATE?

No. DATE has no time or zone component, so PARSE_DATE ignores time zone information. Use PARSE_TIMESTAMP if zone context matters.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo