I have a legacy query in which I am looking data for six weeks as shown below. In my below AND condition I get data for past six weeks and it worked fine in 2020
middle and end. But since 2021
started, this stopped working because of obvious subtraction I am doing with 6.
AND data.week_col::integer BETWEEN DATE_PART(w, CURRENT_DATE) - 6 AND DATE_PART(w, CURRENT_DATE) - 1
There is a bug in above query because of which it stopped working in 2021. How can I change above condition so that it can work entire year without any issues and give me data for past 6 weeks.
Update
Below is my query which I am running:
select *,
dateadd(d, - datepart(dow, trunc(CONVERT_TIMEZONE('UTC','PST8PDT',client_date))), trunc(CONVERT_TIMEZONE('UTC','PST8PDT',client_date)) + 6) as day,
date_part(week, day) as week_col
from holder data
where data.week_col::integer BETWEEN DATE_PART(w, CURRENT_DATE) - 6 AND DATE_PART(w, CURRENT_DATE) - 1
client_date
column has values like this - 2021-01-15 21:30:00.0
. And from that I get value of day
column and from day
column I get value of
week_col
column as shown above.
week_col
column has values like 53
, 52
.... It's a week number in general.
Because of my AND
condition I am getting data for week 1
only but technically I want data for 49
, 50
, 51
, 52
, 53
and 1
as it is past six weeks. Can I use day
column here to get correct past six weeks?