BigQuery · Timestamp function
BigQuery TIMESTAMP_TRUNC
TIMESTAMP_TRUNC(ts, part[, time_zone]) rounds a TIMESTAMP down to the start of a minute, hour, day, week, month or year, in UTC or in the zone you pass. Use it to group events per hour or per local day.
TIMESTAMP_TRUNC returns the first instant of the period that contains ts. Parts range from MICROSECOND to HOUR and from DAY to ISOYEAR, including WEEK (Sunday weeks), WEEK(<WEEKDAY>), ISOWEEK, MONTH and QUARTER.
Periods from MINUTE up are found in a time zone, UTC by default. TIMESTAMP_TRUNC(ts, DAY, 'America/New_York') returns New York midnight, which the console shows as 05:00 UTC in winter and 04:00 UTC in summer. Grouping by the zoned result gives local daily totals while the column stays a TIMESTAMP; DATE(ts, zone) gives the same grouping as a DATE.
TIMESTAMP_TRUNC also accepts a DATETIME (without a zone) and then returns a DATETIME. There is no part for 15 or 5 minutes; use TIMESTAMP_BUCKET or arithmetic on UNIX_SECONDS for those.
Syntax
TIMESTAMP_TRUNC(timestamp_value, timestamp_granularity[, time_zone])
TIMESTAMP_TRUNC(datetime_value, datetime_granularity)Arguments and return value
| Argument | Description |
|---|---|
timestamp_value | The TIMESTAMP to truncate. |
timestamp_granularity | Unquoted: MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, WEEK(<WEEKDAY>), ISOWEEK, MONTH, QUARTER, YEAR or ISOYEAR. |
time_zone | Optional zone used to find the period start, for MINUTE and larger parts. Defaults to UTC. |
Returns: TIMESTAMP (or DATETIME when the input is a DATETIME).
Examples
Truncate to hour, day, Monday week and month
SELECT
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-25 18:45:30+00', HOUR) AS hour_start,
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-25 18:45:30+00', DAY) AS day_start,
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-25 18:45:30+00', WEEK(MONDAY)) AS week_start,
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-25 18:45:30+00', MONTH) AS month_start;| hour_start | day_start | week_start | month_start |
|---|---|---|---|
| 2026-11-25 18:00:00 UTC | 2026-11-25 00:00:00 UTC | 2026-11-23 00:00:00 UTC | 2026-11-01 00:00:00 UTC |
Local midnight in different zones
In New York the event is on November 22 (22:30 local); in Tokyo it is on November 23 (12:30 local).
SELECT
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-23 03:30:00+00', DAY) AS utc_day,
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-23 03:30:00+00', DAY, 'America/New_York') AS new_york_day,
TIMESTAMP_TRUNC(TIMESTAMP '2026-11-23 03:30:00+00', DAY, 'Asia/Tokyo') AS tokyo_day;| utc_day | new_york_day | tokyo_day |
|---|---|---|
| 2026-11-23 00:00:00 UTC | 2026-11-22 05:00:00 UTC | 2026-11-22 15:00:00 UTC |
Events per hour
WITH events AS (
SELECT TIMESTAMP '2026-11-23 08:05:00+00' AS event_ts UNION ALL
SELECT TIMESTAMP '2026-11-23 08:59:59.999+00' UNION ALL
SELECT TIMESTAMP '2026-11-23 09:00:00+00'
)
SELECT TIMESTAMP_TRUNC(event_ts, HOUR) AS hour, COUNT(*) AS events
FROM events
GROUP BY hour
ORDER BY hour;| hour | events |
|---|---|
| 2026-11-23 08:00:00 UTC | 2 |
| 2026-11-23 09:00:00 UTC | 1 |
Common mistakes
- Using PostgreSQL argument order.
DATE_TRUNC('hour', ts)fails; writeTIMESTAMP_TRUNC(ts, HOUR). - Grouping by UTC days for a local business. Pass the zone:
TIMESTAMP_TRUNC(ts, DAY, 'Europe/Madrid'), or group byDATE(ts, 'Europe/Madrid'). - Expecting Monday weeks from
WEEK. It starts on Sunday; useWEEK(MONDAY)orISOWEEK. - Passing a zone with a DATETIME. The zone argument is only for TIMESTAMP input.
Cost and performance
- TIMESTAMP_TRUNC on the partitioning column (for example
TIMESTAMP_TRUNC(ts, MONTH) >= '2026-04-01') still allows partition pruning according to BigQuery's pruning guide. Check the bytes estimate with a dry run when you add a time zone argument. - To chart slot usage or spend per hour from job metadata, truncate
creation_timethe same way, as in slot usage by hour.
FAQ
How do I truncate a timestamp to the day in my time zone?
TIMESTAMP_TRUNC(ts, DAY, 'Europe/Prague') returns local midnight as a TIMESTAMP. DATE(ts, 'Europe/Prague') returns the local calendar date.
What is the difference between TIMESTAMP_TRUNC and DATE_TRUNC?
Both accept a TIMESTAMP and a zone in current BigQuery. DATE_TRUNC is the general form for DATE, DATETIME and TIMESTAMP; TIMESTAMP_TRUNC is the long-standing timestamp-specific name and returns the same TIMESTAMP.
How do I group timestamps into 15-minute buckets?
Use TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(ts), 900) * 900), or TIMESTAMP_BUCKET with INTERVAL 15 MINUTE.
Related
Errors you may hit
More timestamp functions
All BigQuery timestamp functions · All functions · BigQuery error messages
