BigQuery · Date function
BigQuery DATE_SUB
DATE_SUB(date, INTERVAL n part) subtracts days, weeks, months, quarters or years from a DATE. DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) is yesterday; month subtraction clamps to the last day of shorter months.
DATE_SUB is DATE_ADD in reverse: it moves a DATE back by DAY, WEEK, MONTH, QUARTER or YEAR units and returns a DATE. It is the usual way to write relative date filters such as "the last 30 days" or "the same day last year".
Month, quarter and year steps keep the day of the month when possible and otherwise return the last day of the target month, so March 31 minus one month is February 28. A negative amount moves forward. WEEK is 7 days.
For days only, d - 1 is shorter and also returns a DATE. Subtracting two dates is different: date_a - date_b returns an INTERVAL such as 0-0 22 0:0:0, not a number. Use DATE_DIFF to get the number of days between two dates.
Syntax
DATE_SUB(date_expression, INTERVAL step_size step_unit)Arguments and return value
| Argument | Description |
|---|---|
date_expression | The DATE to shift back. |
step_size | An INT64 number of units. Negative values move forward. |
step_unit | DAY, WEEK (7 days), MONTH, QUARTER or YEAR. |
Returns: DATE
Examples
Yesterday, last week, last month, last year
SELECT
DATE_SUB(DATE '2026-11-23', INTERVAL 1 DAY) AS yesterday,
DATE_SUB(DATE '2026-11-23', INTERVAL 1 WEEK) AS week_ago,
DATE_SUB(DATE '2026-11-23', INTERVAL 1 MONTH) AS month_ago,
DATE_SUB(DATE '2026-11-23', INTERVAL 1 YEAR) AS year_ago;| yesterday | week_ago | month_ago | year_ago |
|---|---|---|---|
| 2026-11-22 | 2026-11-16 | 2026-10-23 | 2025-11-23 |
Subtracting a month from a month end
SELECT
DATE_SUB(DATE '2026-03-31', INTERVAL 1 MONTH) AS from_mar_31,
DATE_SUB(DATE '2026-05-31', INTERVAL 1 MONTH) AS from_may_31,
DATE_SUB(DATE '2026-03-31', INTERVAL 1 QUARTER) AS quarter_back;| from_mar_31 | from_may_31 | quarter_back |
|---|---|---|
| 2026-02-28 | 2026-04-30 | 2025-12-31 |
Rolling 30-day window ending yesterday
u3 is outside the window and u4 is today, which the filter excludes because today is incomplete.
WITH sessions AS (
SELECT 'u1' AS user_id, CURRENT_DATE() - 2 AS session_date UNION ALL
SELECT 'u2', CURRENT_DATE() - 29 UNION ALL
SELECT 'u3', CURRENT_DATE() - 31 UNION ALL
SELECT 'u4', CURRENT_DATE()
)
SELECT COUNT(DISTINCT user_id) AS active_users_30d
FROM sessions
WHERE session_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
AND session_date < CURRENT_DATE();| active_users_30d |
|---|
| 2 |
Common mistakes
- Using
DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)in a dashboard for a non-UTC audience. CURRENT_DATE() is the UTC date; useCURRENT_DATE('America/Chicago')as the base. - Subtracting two dates to get days.
d1 - d2returns an INTERVAL, andDATE_SUB(d1, d2)fails with "Expected INTERVAL expression". UseDATE_DIFF(d1, d2, DAY). - Writing
DATEADD(day, -1, d)ord - INTERVAL '1 day'from Snowflake or PostgreSQL. UseDATE_SUB(d, INTERVAL 1 DAY)ord - 1. - Expecting
d - INTERVAL 1 DAYto return a DATE. Any DATE plus or minus an INTERVAL returns a DATETIME;d - 1keeps the DATE type.
Cost and performance
- On a date-partitioned table, filters such as
order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY)still prune partitions, because the right-hand side is a constant expression. DATE_ADD, DATE_SUB, DATE_DIFF and DATE_TRUNC are also on BigQuery's list of functions that can wrap the partitioning column without blocking pruning; check the estimate with a dry run before scheduling the query.
FAQ
How do I get the current date minus 1 day in BigQuery?
DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) or CURRENT_DATE() - 1. Add a time zone argument to CURRENT_DATE if yesterday should follow local time.
How do I filter the last 7 days?
WHERE d >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY). Add AND d < CURRENT_DATE() if today's partial data should be excluded.
What does March 31 minus one month return?
February 28 (or 29 in a leap year). DATE_SUB clamps to the last day of the target month when the day doesn't exist there.
Related
Errors you may hit
More date functions
All BigQuery date functions · All functions · BigQuery error messages
