BigQuery · Timestamp function
BigQuery PARSE_TIMESTAMP
PARSE_TIMESTAMP(format_string, string[, time_zone]) converts a STRING to a TIMESTAMP using % elements. An offset in the text (%z, %Ez) is honored; otherwise the text is read in the zone argument, or UTC by default.
PARSE_TIMESTAMP reads a date and time in a known layout and returns an instant. If the string carries its own offset, parse it with %Ez (+01:00) or %z (+0100), and that offset decides the instant even when you also pass a zone argument. If it has no offset, the optional third argument says which zone the text is in; without it, UTC.
The whole string must match. A literal Z at the end of ISO strings can be matched as plain text ('%Y-%m-%dT%H:%M:%SZ'), %E*S accepts any number of fractional digits, and %s reads epoch seconds. Fields missing from the format default to 1970-01-01 00:00:00 in the zone used. Names and AM/PM are case-insensitive; %P is not allowed for parsing.
A value that doesn't match fails the query with Failed to parse input string. On raw logs, use SAFE.PARSE_TIMESTAMP to get NULL instead. For canonical strings, TIMESTAMP(s) or CAST(s AS TIMESTAMP) is enough.
Syntax
PARSE_TIMESTAMP(format_string, timestamp_string[, time_zone])Arguments and return value
| Argument | Description |
|---|---|
format_string | A STRING of format elements describing the input. |
timestamp_string | The STRING to parse. NULL returns NULL. |
time_zone | Optional zone for text without an offset. Defaults to UTC. Ignored for the offset when the text contains one. |
Returns: TIMESTAMP
Examples
Offsets, zone argument and Zulu time
SELECT
PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S%Ez', '2026-11-23 10:00:00+01:00') AS rfc3339_offset,
PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S %z', '2026-11-23 10:00:00 +0100') AS numeric_offset,
PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', '2026-11-23 10:00:00', 'Europe/Berlin') AS zone_argument,
PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%SZ', '2026-11-23T10:00:00Z') AS zulu;| rfc3339_offset | numeric_offset | zone_argument | zulu |
|---|---|---|---|
| 2026-11-23 09:00:00 UTC | 2026-11-23 09:00:00 UTC | 2026-11-23 09:00:00 UTC | 2026-11-23 10:00:00 UTC |
An offset in the text wins over the zone argument
SELECT PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S%Ez', '2026-11-23 10:00:00+01:00', 'America/New_York') AS parsed;| parsed |
|---|
| 2026-11-23 09:00:00 UTC |
Apache-style log timestamps
Both valid lines describe the same instant. SAFE returns NULL for line 3 instead of failing the query.
WITH logs AS (
SELECT 1 AS line, '23/Nov/2026:18:45:30 +0000' AS ts_text UNION ALL
SELECT 2, '23/Nov/2026:19:45:30 +0100' UNION ALL
SELECT 3, 'not a date'
)
SELECT line, SAFE.PARSE_TIMESTAMP('%d/%b/%Y:%H:%M:%S %z', ts_text) AS logged_at
FROM logs
ORDER BY line;| line | logged_at |
|---|---|
| 1 | 2026-11-23 18:45:30 UTC |
| 2 | 2026-11-23 18:45:30 UTC |
| 3 | NULL |
Epoch seconds as text
SELECT PARSE_TIMESTAMP('%s', '1795392000') AS from_epoch;| from_epoch |
|---|
| 2026-11-23 00:00:00 UTC |
Common mistakes
- Dropping the offset. Parsing
'2026-11-23 10:00:00+01:00'with PARSE_DATETIME, or with a format that matches+01:00as literal text, loses the offset and shifts the instant. - Expecting the zone argument to override an explicit offset. When the text has
%zor%Ez, that offset is used. - Porting
TO_TIMESTAMP(s, 'YYYY-MM-DD HH24:MI:SS')from PostgreSQL, Oracle or Snowflake. BigQuery uses % elements, and the format string comes first. - Parsing epoch milliseconds with
%s.%sis seconds; for milliseconds use TIMESTAMP_MILLIS(CAST(s AS INT64)).
Cost and performance
- Parse text timestamps once during load or in a staging model and store a TIMESTAMP column you can partition on. Parsing in every query costs slots and can't prune partitions.
FAQ
How do I convert a string to a timestamp in BigQuery?
TIMESTAMP('2026-11-23 10:00:00+01') or CAST(s AS TIMESTAMP) for canonical strings; PARSE_TIMESTAMP(format, s) for anything else, such as PARSE_TIMESTAMP('%d/%m/%Y %H:%M', '23/11/2026 10:00').
How do I parse an ISO 8601 timestamp with an offset?
PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%E*S%Ez', s) handles 2026-11-23T10:00:00.25+01:00. For a trailing Z, put a literal Z in the format: '%Y-%m-%dT%H:%M:%E*SZ'.
Why do I get "Failed to parse input string"?
The text doesn't match the format exactly, often because of a missing time part, an extra suffix or a different separator. See Failed to parse input string.
Related
Errors you may hit
More timestamp functions
All BigQuery timestamp functions · All functions · BigQuery error messages
