BigQuery · Date function
BigQuery DATE_DIFF
DATE_DIFF(end_date, start_date, DAY) returns the number of days between two dates as INT64. For WEEK, MONTH and YEAR it counts calendar boundaries crossed, so January 31 to February 1 is one month.
DATE_DIFF subtracts start_date from end_date in the unit you choose and returns an INT64. The later date goes first; reversed arguments give a negative number. For DAY the result is simply the number of days between the two dates.
For every other unit, DATE_DIFF counts how many period boundaries lie between the dates, not how many full periods passed. WEEK boundaries fall on Sundays, so Saturday to the next day (Sunday) is 1 week. January 31 to February 1 is 1 MONTH, and December 31 to January 1 is 1 YEAR. Use WEEK(MONDAY) or ISOWEEK for Monday weeks, and compute full months or years yourself when you need age or tenure.
The function also accepts two DATETIME or two TIMESTAMP values and then behaves like DATETIME_DIFF or TIMESTAMP_DIFF. Mixing a DATE with a TIMESTAMP raises No matching signature.
Syntax
DATE_DIFF(end_date, start_date, granularity)Arguments and return value
| Argument | Description |
|---|---|
end_date | The later DATE. If it is earlier than start_date, the result is 0 or negative. |
start_date | The earlier DATE. |
granularity | DAY, WEEK (weeks start on Sunday), WEEK(<WEEKDAY>), ISOWEEK, MONTH, QUARTER, YEAR or ISOYEAR. Unquoted. |
Returns: INT64
Examples
Days between two dates
SELECT
DATE_DIFF(DATE '2026-11-23', DATE '2026-11-01', DAY) AS days_since,
DATE_DIFF(DATE '2026-11-01', DATE '2026-11-23', DAY) AS reversed;| days_since | reversed |
|---|---|
| 22 | -22 |
Week boundaries: Sunday weeks versus Monday weeks
2026-11-16 is a Monday and 2026-11-22 is a Sunday. The range crosses one Sunday boundary but no Monday boundary.
SELECT
DATE_DIFF(DATE '2026-11-22', DATE '2026-11-16', DAY) AS days,
DATE_DIFF(DATE '2026-11-22', DATE '2026-11-16', WEEK) AS weeks_sunday,
DATE_DIFF(DATE '2026-11-22', DATE '2026-11-16', WEEK(MONDAY)) AS weeks_monday,
DATE_DIFF(DATE '2026-11-22', DATE '2026-11-16', ISOWEEK) AS iso_weeks;| days | weeks_sunday | weeks_monday | iso_weeks |
|---|---|---|---|
| 6 | 1 | 0 | 0 |
One day apart can be one month or one year
SELECT
DATE_DIFF(DATE '2026-02-01', DATE '2026-01-31', MONTH) AS months_1_day,
DATE_DIFF(DATE '2026-01-31', DATE '2026-01-01', MONTH) AS months_30_days,
DATE_DIFF(DATE '2027-01-01', DATE '2026-12-31', YEAR) AS years_1_day;| months_1_day | months_30_days | years_1_day |
|---|---|---|
| 1 | 0 | 1 |
Full years of tenure
c1 signed up on December 1, 2024: two year boundaries, but only one full year by November 23, 2026. Subtract 1 when the anniversary hasn't come yet this year.
WITH customers AS (
SELECT 'c1' AS customer_id, DATE '2024-12-01' AS signup_date UNION ALL
SELECT 'c2', DATE '2025-11-23' UNION ALL
SELECT 'c3', DATE '2020-02-29'
)
SELECT
customer_id,
DATE_DIFF(DATE '2026-11-23', signup_date, YEAR) AS year_boundaries,
DATE_DIFF(DATE '2026-11-23', signup_date, YEAR)
- IF(FORMAT_DATE('%m%d', DATE '2026-11-23') < FORMAT_DATE('%m%d', signup_date), 1, 0) AS full_years
FROM customers
ORDER BY customer_id;| customer_id | year_boundaries | full_years |
|---|---|---|
| c1 | 2 | 1 |
| c2 | 1 | 1 |
| c3 | 6 | 6 |
Common mistakes
- Using the Snowflake or SQL Server argument order.
DATEDIFF(day, start, end)is "Function not found", andDATE_DIFF(day, start, end)fails with "Unrecognized name: day". BigQuery puts the end date first and the unit last. - Reading MONTH or YEAR results as completed periods. DATE_DIFF counts boundaries, so
DATE_DIFF('2026-02-01', '2026-01-31', MONTH)is 1. For age or tenure, subtract 1 when the anniversary hasn't been reached. - Expecting Monday weeks from
WEEK.WEEKboundaries are Sundays; useWEEK(MONDAY)orISOWEEK. - Subtracting dates with
-to get a number.d1 - d2returns an INTERVAL like0-0 22 0:0:0;DATE_DIFF(d1, d2, DAY)returns 22. - Mixing types.
DATE_DIFF(order_date, shipped_at, DAY)with a TIMESTAMPshipped_athas no matching signature; convert withDATE(shipped_at, 'Europe/Paris')first.
Cost and performance
- DATE_DIFF is on BigQuery's list of functions that can wrap a partitioning column and still allow partition pruning, as long as its other arguments are constants. A plain range filter (
d >= '2026-11-01') is still the clearest option; confirm the bytes with a dry run.
FAQ
How do I get the date difference in days in BigQuery?
DATE_DIFF(end_date, start_date, DAY). The later date goes first; the result is an INT64 and is negative when the dates are reversed.
Why does DATE_DIFF return 1 week for dates one day apart?
With WEEK, DATE_DIFF counts Sunday boundaries between the dates. Saturday to Sunday crosses one boundary. Divide the DAY difference by 7 if you want elapsed weeks.
What is the difference between DATE_DIFF and TIMESTAMP_DIFF?
DATE_DIFF on dates counts calendar boundaries, including WEEK, MONTH and YEAR. TIMESTAMP_DIFF counts whole elapsed units up to DAY and doesn't support WEEK, MONTH or YEAR.
How do I calculate someone's age in BigQuery?
Take DATE_DIFF(CURRENT_DATE(), birth_date, YEAR) and subtract 1 when FORMAT_DATE('%m%d', CURRENT_DATE()) < FORMAT_DATE('%m%d', birth_date).
Related
Errors you may hit
More date functions
All BigQuery date functions · All functions · BigQuery error messages
