would anyone be able to advise on how to bring in results from the last 2 calendar years? I'd like this to be dynamic, and show data from the current year + the previous year.
I'm currently using MYDATE > current_date - interval '2' year
, but this is giving me all data from the last 2 years starting today, so is going back into 2021.
Any help would be greatly appreciated!
I am trying to pull in results from the last 2 calendar years only
You can try to use
date_trunc
.For example
MYDATE >= date_trunc('year', current_date - interval '1' year)
.Running the above filter (on the 2023-11-15 of November), then it gets evaluated with:
MYDATE >= '2022-01-01'
, so you have data from the previous year (complete) and for the partially current year.