Request a demo

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.

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

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

ArgumentDescription
date_expressionThe DATE to shift back.
step_sizeAn INT64 number of units. Negative values move forward.
step_unitDAY, 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;
Result
yesterdayweek_agomonth_agoyear_ago
2026-11-222026-11-162026-10-232025-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;
Result
from_mar_31from_may_31quarter_back
2026-02-282026-04-302025-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();
Result
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; use CURRENT_DATE('America/Chicago') as the base.
  • Subtracting two dates to get days. d1 - d2 returns an INTERVAL, and DATE_SUB(d1, d2) fails with "Expected INTERVAL expression". Use DATE_DIFF(d1, d2, DAY).
  • Writing DATEADD(day, -1, d) or d - INTERVAL '1 day' from Snowflake or PostgreSQL. Use DATE_SUB(d, INTERVAL 1 DAY) or d - 1.
  • Expecting d - INTERVAL 1 DAY to return a DATE. Any DATE plus or minus an INTERVAL returns a DATETIME; d - 1 keeps 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.

Errors you may hit

More date functions

All BigQuery date 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.