Mike5298
Mike5298

Reputation: 385

How can I set up a BigQuery query with a date range includes the current date

I'm trying to query a database of hits in BigQuery starting at a specified go live date and I want the query to continuously run each day afterwards. Is there a way to prevent hard coding a date range into a query but have the current date instead?

What I've got so far is

WHERE SUBSTR(_TABLE_SUFFIX, 1, 8) BETWEEN '20200701' AND '20211231'

Its the second date that I want to change to be some sort of variable for the current date?

Thanks

Upvotes: 0

Views: 97

Answers (1)

Sergey Geron
Sergey Geron

Reputation: 10152

Use CURRENT_DATE() with FORMAT_DATE():

SELECT FORMAT_DATE("%Y%m%d", CURRENT_DATE()) AS formatted;

enter image description here

Upvotes: 1

Related Questions