BigQuery · Timestamp function
BigQuery FORMAT_TIMESTAMP
FORMAT_TIMESTAMP(format_string, ts[, time_zone]) converts a TIMESTAMP to a STRING with % elements, in UTC or in the zone you pass: FORMAT_TIMESTAMP('%F %H:%M', ts, 'Europe/Berlin'). It is the standard way to turn a timestamp into a local-time string.
FORMAT_TIMESTAMP prints an instant as text. The optional third argument decides which zone's wall clock is printed; without it the output is UTC. Besides the date and time elements shared with FORMAT_DATETIME, it supports zone elements: %z prints the offset as +0530, %Ez as +05:30 (RFC 3339), and %Z the zone as BigQuery names it, such as UTC or UTC-5, not abbreviations like EST.
Common layouts: '%Y-%m-%dT%H:%M:%SZ' for ISO 8601 in UTC, '%Y-%m-%dT%H:%M:%E3S%Ez' for ISO with milliseconds and an offset, '%F %T' for 2026-11-23 15:30:00, and '%s' for epoch seconds as text.
CAST(ts AS STRING) is the quick alternative and returns 2026-11-23 15:30:00+00; STRING(ts, 'Asia/Tokyo') does the same in another zone. Use FORMAT_TIMESTAMP when the consumer needs a specific layout.
Syntax
FORMAT_TIMESTAMP(format_string, timestamp_expr[, time_zone])Arguments and return value
| Argument | Description |
|---|---|
format_string | A STRING of format elements and literal text. |
timestamp_expr | The TIMESTAMP to format. NULL returns NULL. |
time_zone | Optional zone name or offset whose local time is printed. Defaults to UTC. |
Returns: STRING
Examples
ISO 8601 and other common layouts
SELECT
FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%SZ', TIMESTAMP '2026-11-23 15:30:00+00') AS iso_utc,
FORMAT_TIMESTAMP('%F %T', TIMESTAMP '2026-11-23 15:30:00+00') AS sql_style,
FORMAT_TIMESTAMP('%c', TIMESTAMP '2026-11-23 15:30:00+00') AS readable,
CAST(TIMESTAMP '2026-11-23 15:30:00+00' AS STRING) AS cast_default;| iso_utc | sql_style | readable | cast_default |
|---|---|---|---|
| 2026-11-23T15:30:00Z | 2026-11-23 15:30:00 | Mon Nov 23 15:30:00 2026 | 2026-11-23 15:30:00+00 |
Local time with the zone or offset
SELECT
FORMAT_TIMESTAMP('%Y-%m-%d %H:%M %Z', TIMESTAMP '2026-11-23 15:30:00+00', 'America/New_York') AS new_york,
FORMAT_TIMESTAMP('%H:%M%Ez', TIMESTAMP '2026-11-23 15:30:00+00', 'Europe/Berlin') AS berlin_rfc3339,
FORMAT_TIMESTAMP('%H:%M %z', TIMESTAMP '2026-11-23 15:30:00+00', 'Asia/Kolkata') AS kolkata;| new_york | berlin_rfc3339 | kolkata |
|---|---|---|
| 2026-11-23 10:30 UTC-5 | 16:30+01:00 | 21:00 +0530 |
Milliseconds for APIs and logs
SELECT
FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%E3SZ', TIMESTAMP '2026-11-23 15:30:00.123456+00') AS iso_millis,
FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%E*S%Ez', TIMESTAMP '2026-11-23 15:30:00.123456+00', 'Europe/Berlin') AS iso_micros_berlin;| iso_millis | iso_micros_berlin |
|---|---|
| 2026-11-23T15:30:00.123Z | 2026-11-23T16:30:00.123456+01:00 |
Local hour labels for a report
WITH orders AS (
SELECT TIMESTAMP '2026-11-23 07:10:00+00' AS created_at UNION ALL
SELECT TIMESTAMP '2026-11-23 07:50:00+00' UNION ALL
SELECT TIMESTAMP '2026-11-23 12:20:00+00'
),
hourly AS (
SELECT TIMESTAMP_TRUNC(created_at, HOUR, 'Europe/Berlin') AS hour, COUNT(*) AS orders
FROM orders
GROUP BY hour
)
SELECT FORMAT_TIMESTAMP('%H:00', hour, 'Europe/Berlin') AS berlin_hour, orders
FROM hourly
ORDER BY hour;| berlin_hour | orders |
|---|---|
| 08:00 | 2 |
| 13:00 | 1 |
Common mistakes
- Forgetting the zone argument. Without it the string is UTC, which shifts hours and sometimes dates for local reports.
- Expecting
%Zto print EST or CET. BigQuery prints names such asUTC-5orUTC+1; print the offset with%Ezor add the zone name as literal text. - Formatting the partition column in WHERE. Only
%F,%Y-%m-%dand%Y%m%dkeep partition pruning; other layouts scan every partition. - Porting
TO_CHAR(ts AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS')from PostgreSQL. Use FORMAT_TIMESTAMP with % elements, orCAST(ts AS STRING FORMAT ... AT TIME ZONE ...).
Cost and performance
- BigQuery's partition pruning guide lists FORMAT_TIMESTAMP with
%F,%Y-%m-%dor%Y%m%das safe to use on the partitioning column. Any other format string in a filter forces a scan of all partitions.
FAQ
How do I convert a timestamp to a string in BigQuery?
CAST(ts AS STRING) returns 2026-11-23 15:30:00+00. For any other layout or a local zone, use FORMAT_TIMESTAMP('%F %T', ts, 'America/Chicago').
How do I format a timestamp as ISO 8601?
FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%SZ', ts) for UTC, or FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%S%Ez', ts, zone) with a local offset. Add %E3S instead of %S for milliseconds.
How do I show a timestamp in a different time zone?
Pass the zone as the third argument: FORMAT_TIMESTAMP('%F %H:%M', ts, 'Australia/Sydney'). For a DATETIME value instead of a string, use DATETIME(ts, 'Australia/Sydney').
Related
Errors you may hit
More timestamp functions
All BigQuery timestamp functions · All functions · BigQuery error messages
