Reputation: 1998
I have a filter in my query such as:
where business_day BETWEEN date_add('day',-14, CURRENT_DATE) AND date_add('day',-2,CURRENT_DATE)
How can I tweak this to where it is just 14 days prior to current date and not 14 days from 2 days prior? Just replacing -2 with 0 in latter part of clause as:
where business_day BETWEEN date_add('day',-14, CURRENT_DATE) AND date_add('day',0,CURRENT_DATE)
or would there be cleaner way for that?
Thanks!
Upvotes: 0
Views: 264
Reputation: 222482
This expression is a no-op:
date_add('day',0,CURRENT_DATE)
It actually returns CURRENT_DATE
.
I find that date arithmetics is easier to undersand using the interval
syntax. If you have no dates in the future, you can do:
where business_day >= current_date - interval '14' day
If there are dates in the future, then:
where business_day >= current_date - interval '14' day and business_day <= current_date
Upvotes: 1