Reputation: 181
I am trying to grab the following date ranges:
I have the following query, but it doesn't seem to work:
OR date(date) >= date(dateadd(week,-6, current_date))
OR date(date) >= date(dateadd(week,-55, current_date))
OR date(date) <= date(dateadd(week,-51, current_date))
Any ideas?
Upvotes: 0
Views: 3022
Reputation: 2757
You should use AND for specifying the date range. Try the following where condition.
date(date) >= date(dateadd(week,-6, current_date))
OR (
date(date) >= date(dateadd(week,-55, current_date))
AND
date(date) <= date(dateadd(week,-51, current_date))
)
Upvotes: 2
Reputation:
You would need to use date arithmetics:
select *
from the_table
where the_date_column <= current_date - interval '6 week'
or the_date_column between
current_date - interval '55 week'
and current_date - interval '51 week';
If the_date_column
is actually a timestamp
column (not a date
column) you might want to cast it to a date
to get rid of the time part using the_date_column::date
The manual explains all available date/time functions:
http://www.postgresql.org/docs/current/static/functions-datetime.html
Upvotes: 0