BigQuery · Datetime function
BigQuery PARSE_DATETIME
PARSE_DATETIME(format_string, string) converts a STRING to a DATETIME using % elements, such as PARSE_DATETIME('%d/%m/%Y %H:%M', '23/11/2026 18:45'). The result has no time zone; wrap it in TIMESTAMP(..., zone) to get an instant.
PARSE_DATETIME reads a date and time written in a known layout. Every part of the string must match the format: %Y-%m-%d %H:%M:%S for 2026-11-23 18:45:30, %m/%d/%Y %I:%M %p for 11/23/2026 6:45 PM. Fields missing from the format default to 1970-01-01 00:00:00, names and AM/PM markers are case-insensitive, and %E*S accepts any number of fractional digits.
The result is a civil DATETIME. If the strings are local times from a known zone, convert them to instants with TIMESTAMP(PARSE_DATETIME(...), 'America/Chicago'). If they carry an offset such as +01:00, use PARSE_TIMESTAMP with %Ez instead, which keeps the offset.
A value that doesn't match fails the query with Failed to parse input string. Use SAFE.PARSE_DATETIME on raw data to get NULL instead. %P can't be used for parsing; use %p.
Syntax
PARSE_DATETIME(format_string, datetime_string)Arguments and return value
| Argument | Description |
|---|---|
format_string | A STRING of format elements describing the input. |
datetime_string | The STRING to parse. NULL returns NULL. |
Returns: DATETIME
Examples
Parse common layouts
SELECT
PARSE_DATETIME('%Y-%m-%d %H:%M:%S', '2026-11-23 18:45:30') AS iso_style,
PARSE_DATETIME('%d/%m/%Y %H:%M', '23/11/2026 18:45') AS european,
PARSE_DATETIME('%m/%d/%Y %I:%M %p', '11/23/2026 6:45 pm') AS us_12_hour;| iso_style | european | us_12_hour |
|---|---|---|
| 2026-11-23T18:45:30 | 2026-11-23T18:45:00 | 2026-11-23T18:45:00 |
ISO 8601 with a T and microseconds
SELECT PARSE_DATETIME('%Y-%m-%dT%H:%M:%E*S', '2026-11-23T18:45:30.123456') AS parsed;| parsed |
|---|
| 2026-11-23T18:45:30.123456 |
Local store times to UTC instants
WITH receipts AS (
SELECT 'r1' AS receipt_id, '23.11.2026 09:15' AS local_text UNION ALL
SELECT 'r2', '23.11.2026 21:40'
)
SELECT
receipt_id,
TIMESTAMP(PARSE_DATETIME('%d.%m.%Y %H:%M', local_text), 'Europe/Berlin') AS sold_at
FROM receipts
ORDER BY receipt_id;| receipt_id | sold_at |
|---|---|
| r1 | 2026-11-23 08:15:00 UTC |
| r2 | 2026-11-23 20:40:00 UTC |
Bad values become NULL with SAFE
SELECT
SAFE.PARSE_DATETIME('%Y-%m-%d %H:%M:%S', '2026-11-23') AS missing_time,
SAFE.PARSE_DATETIME('%Y-%m-%d %H:%M:%S', '2026-11-23 25:00:00') AS bad_hour;| missing_time | bad_hour |
|---|---|
| NULL | NULL |
Common mistakes
- Parsing strings that end in
Zor an offset and dropping it. PARSE_DATETIME can't keep an offset; use PARSE_TIMESTAMP with%Ezor%z. - Assuming the result is UTC. A DATETIME has no zone; decide which zone the text was written in and convert with TIMESTAMP(dt, zone).
- Using
%Pin a parse format. Only%pworks for parsing, and it accepts am, AM, pm and PM. - Swapping the arguments or porting
TO_TIMESTAMP(s, 'DD/MM/YYYY HH24:MI')from other databases. The format string comes first and uses % elements.
Cost and performance
- Parse text timestamps once in a staging step and store a typed column. Parsing in every query costs slots and prevents partition pruning on the derived value.
FAQ
How do I convert a string to a datetime in BigQuery?
CAST('2026-11-23 18:45:30' AS DATETIME) works for the canonical layout. For anything else use PARSE_DATETIME(format, s), for example PARSE_DATETIME('%d/%m/%Y %H:%M', '23/11/2026 18:45').
Should I use PARSE_DATETIME or PARSE_TIMESTAMP?
Use PARSE_TIMESTAMP when the text is an instant (it has an offset or is known to be UTC). Use PARSE_DATETIME for local wall-clock times you want to keep without a zone.
Related
Errors you may hit
More datetime functions
All BigQuery datetime functions · All functions · BigQuery error messages
