Truncates a DATE to the specified granularity (DAY, WEEK, MONTH, QUARTER, YEAR).
DATEDiperbarui: 13 Jun 2026DATE_TRUNC(date_expression, date_part)The DATE to truncate
Granularity: DAY, WEEK, MONTH, QUARTER, YEAR, etc.
1 SELECT 2 date, 3 DATE_TRUNC(date, WEEK) as week_start, 4 DATE_TRUNC(date, MONTH) as month_start, 5 DATE_TRUNC(date, YEAR) as year_start 6 FROM UNNEST([DATE '2024-01-15']) as date;
Truncate a date to various granularities.
| date | week_start | month_start | year_start |
|---|---|---|---|
| 2024-01-15 | 2024-01-14 | 2024-01-01 | 2024-01-01 |
1 SELECT 2 DATE_TRUNC(order_date, MONTH) as month, 3 COUNT(*) as order_count, 4 SUM(amount) as total_amount 5 FROM `project.dataset.orders` 6 GROUP BY month 7 ORDER BY month;
Aggregate sales by month using date truncation.
1 SELECT 2 date, 3 DATE_TRUNC(date, WEEK(MONDAY)) as week_monday 4 FROM UNNEST([DATE '2024-01-15']) as date;
Truncate to the start of the week, with Monday as the first day.
| date | week_monday |
|---|---|
| 2024-01-15 | 2024-01-15 |
Sudah paham DATE_TRUNC? Latih langsung di browser
Latihan interaktif, langsung di browser.