Similar questions have been asked before but I could find no clear answer to this one.
How can get dates for the last week of every month in SQL? I have something like this
select date
from date_table
where date > dateadd(day, -8, dateadd(day, -1, date_trunc('month', current_date)::date
and date <= dateadd(day, -1, date_trunc('month', current_date)::date
but this only gives me the dates for last month's data. Is there a way to get the last week for every month?
The date_table here is a table with every single date, along with their year month and date number etc so I also tried something like
select date
from date_table
where day_of_month >= 22
and day_of_month < 31
but I would want to impose some kind of condition so it works for different months (for eg: for Feb it would give me 20-28 but for Jan it would be 23-31)
Any help is appreciated! I'm pretty new to all this.