BigQuery SQL WHERE Date Between Current Date and -15 Days

Eric Hendershott picture Eric Hendershott · Dec 20, 2016 · Viewed 40.8k times · Source

I am trying to code the following condition in the WHERE clause of SQL in BigQuery, but I am having difficulty with the syntax, specifically date math:

WHERE date_column between current_date() and current_date() - 15 days

This seems easy in MySQL, but I can't get it to work with BigQuery SQL.

Answer

JohnHC picture JohnHC · Dec 20, 2016

Use DATE_SUB

select * 
from TableA
where Date_Column between DATE_SUB(current_date(), INTERVAL 15 DAY) and current_date()

Remember, between needs the oldest date first