Request a demo

BigQuery · Datetime function

BigQuery DATETIME_TRUNC

DATETIME_TRUNC(datetime, part) rounds a DATETIME down to the start of a period, such as the hour, day, week or month. Use it to group local wall-clock times into hourly or daily buckets.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

DATETIME_TRUNC returns the beginning of the period that contains the value, keeping the DATETIME type. Supported parts are MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK (weeks start on Sunday), WEEK(<WEEKDAY>), ISOWEEK, MONTH, QUARTER, YEAR and ISOYEAR.

It also accepts a TIMESTAMP with an optional time zone, in which case it returns a TIMESTAMP, exactly like TIMESTAMP_TRUNC. On DATETIME values there is no zone to pass: the value is truncated as it reads.

There is no 15-minute or 5-minute part. For fixed-width buckets, round the minutes yourself (DATETIME_TRUNC(dt, HOUR) + INTERVAL DIV(EXTRACT(MINUTE FROM dt), 15) * 15 MINUTE) or use DATETIME_BUCKET.

Syntax

DATETIME_TRUNC(datetime_value, datetime_granularity)

DATETIME_TRUNC(timestamp_value, timestamp_granularity[, time_zone])

Arguments and return value

ArgumentDescription
datetime_valueThe DATETIME to truncate.
datetime_granularityUnquoted part: MICROSECOND to HOUR, or DAY, WEEK, WEEK(<WEEKDAY>), ISOWEEK, MONTH, QUARTER, YEAR, ISOYEAR.
time_zoneTIMESTAMP input only: the zone in which to find the period start. Defaults to UTC.

Returns: The type of the first argument: DATETIME for DATETIME input, TIMESTAMP for TIMESTAMP input.

Examples

Truncate to hour, day, Monday week and month

SELECT
  DATETIME_TRUNC(DATETIME '2026-11-25 18:45:30', HOUR) AS hour_start,
  DATETIME_TRUNC(DATETIME '2026-11-25 18:45:30', DAY) AS day_start,
  DATETIME_TRUNC(DATETIME '2026-11-25 18:45:30', WEEK(MONDAY)) AS week_start,
  DATETIME_TRUNC(DATETIME '2026-11-25 18:45:30', MONTH) AS month_start;
Result
hour_startday_startweek_startmonth_start
2026-11-25T18:00:002026-11-25T00:00:002026-11-23T00:00:002026-11-01T00:00:00

Check-ins per hour of local time

WITH checkins AS (
  SELECT DATETIME '2026-11-23 08:05:00' AS local_time UNION ALL
  SELECT DATETIME '2026-11-23 08:59:59' UNION ALL
  SELECT DATETIME '2026-11-23 09:00:00'
)
SELECT DATETIME_TRUNC(local_time, HOUR) AS hour, COUNT(*) AS checkins
FROM checkins
GROUP BY hour
ORDER BY hour;
Result
hourcheckins
2026-11-23T08:00:002
2026-11-23T09:00:001

15-minute buckets

SELECT
  DATETIME_TRUNC(DATETIME '2026-11-23 18:47:10', HOUR)
    + INTERVAL DIV(EXTRACT(MINUTE FROM DATETIME '2026-11-23 18:47:10'), 15) * 15 MINUTE AS quarter_hour;
Result
quarter_hour
2026-11-23T18:45:00

TIMESTAMP input returns a TIMESTAMP

03:30 UTC is 22:30 on November 22 in New York, whose local midnight is 05:00 UTC.

SELECT DATETIME_TRUNC(TIMESTAMP '2026-11-23 03:30:00+00', DAY, 'America/New_York') AS ny_day_start;
Result
ny_day_start
2026-11-22 05:00:00 UTC

Common mistakes

  • Writing PostgreSQL order. DATE_TRUNC('hour', dt) fails; BigQuery takes the value first and an unquoted part: DATETIME_TRUNC(dt, HOUR).
  • Expecting Monday weeks from WEEK. It starts on Sunday; use WEEK(MONDAY) or ISOWEEK.
  • Truncating a UTC DATETIME to DAY when the business day is local. Convert first with DATETIME(ts, 'Asia/Tokyo'), then truncate.

Cost and performance

  • DATETIME_TRUNC is not on the documented list of functions that keep partition pruning (TIMESTAMP_TRUNC and DATE_TRUNC are). On a DATETIME-partitioned table, filter the column with a plain range and truncate only in SELECT and GROUP BY.

FAQ

How do I truncate a datetime to the hour in BigQuery?

DATETIME_TRUNC(dt, HOUR) returns the DATETIME at the start of the hour, for example 2026-11-23T18:00:00.

What is the difference between DATETIME_TRUNC and TIMESTAMP_TRUNC?

DATETIME_TRUNC works on wall-clock values without a zone. TIMESTAMP_TRUNC truncates an instant in a time zone (UTC by default) and returns a TIMESTAMP.

Errors you may hit

More datetime functions

All BigQuery datetime functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.