Subtracting days using DATE_SUB Syntax in Google Bigquery

To subtract days, months, years from a date, use the DATE_SUB Function

SELECT DATE_SUB(DATE "2008-12-25", INTERVAL 5 DAY) as five_days_ago;
+--------------------+
| five_days_ago |
+--------------------+
| 2008-12-20 |
+--------------------+

Other examples:

SELECT DATE_SUB(DATE "2008-12-25", INTERVAL 1 WEEK) as one_week_ago;
SELECT DATE_SUB(DATE "2008-12-25", INTERVAL 1 MONTH) as one_month_ago;
SELECT DATE_SUB(DATE "2008-12-25", INTERVAL 1 QUARTER) as one_qtr_ago;
SELECT DATE_SUB(DATE "2008-12-25", INTERVAL 1 YEAR) as one_year_ago;

nVector

posted on 22 Sep 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds