Calculates the difference between two DATE values in the specified unit. Returns an integer value.
INT64Diperbarui: 13 Jun 2026DATE_DIFF(date_expression_a, date_expression_b, date_part)The end DATE (minuend)
The start DATE (subtrahend)
Result unit: DAY, WEEK, MONTH, QUARTER, YEAR
1 SELECT 2 name, 3 birth_date, 4 DATE_DIFF(CURRENT_DATE(), birth_date, YEAR) as age_years, 5 DATE_DIFF(CURRENT_DATE(), birth_date, DAY) as age_days 6 FROM `project.dataset.users`;
Calculate age in years and days.
| name | birth_date | age_years | age_days |
|---|---|---|---|
| John | 1990-05-15 | 33 | 12298 |
1 SELECT 2 order_id, 3 order_date, 4 LAG(order_date) OVER (PARTITION BY customer_id ORDER BY order_date) as prev_order, 5 DATE_DIFF(order_date, LAG(order_date) OVER (PARTITION BY customer_id ORDER BY order_date), DAY) as days_since_last 6 FROM `project.dataset.orders`;
Calculate the number of days between a customer's orders.
1 SELECT 2 employee_id, 3 hire_date, 4 DATE_DIFF(CURRENT_DATE(), hire_date, MONTH) as months_employed 5 FROM `project.dataset.employees` 6 WHERE status = 'active';
Calculate tenure in months.
Sudah paham DATE_DIFF? Latih langsung di browser
Latihan interaktif, langsung di browser.