Truncates a DATETIME value to the specified granularity. Supports all date parts from MICROSECOND through YEAR.
DATETIMEDiperbarui: 13 Jun 2026DATETIME_TRUNC(datetime_expression, datetime_part)The DATETIME value to truncate
Granularity: YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, etc.
1 SELECT 2 dt, 3 DATETIME_TRUNC(dt, HOUR) as hour, 4 DATETIME_TRUNC(dt, DAY) as day, 5 DATETIME_TRUNC(dt, MONTH) as month 6 FROM UNNEST([DATETIME '2024-01-15 14:35:42']) as dt;
Truncate a datetime value to various granularities.
| dt | hour | day | month |
|---|---|---|---|
| 2024-01-15T14:35:42 | 2024-01-15T14:00:00 | 2024-01-15T00:00:00 | 2024-01-01T00:00:00 |
1 SELECT 2 DATETIME_TRUNC(event_datetime, HOUR) as hour, 3 COUNT(*) as events, 4 SUM(revenue) as total_revenue 5 FROM `project.dataset.sales` 6 GROUP BY hour 7 ORDER BY hour;
Aggregate sales revenue by hour.
Sudah paham DATETIME_TRUNC? Latih langsung di browser
Latihan interaktif, langsung di browser.