Reputation: 35
I am trying to get last weeknumber when week is first week of the year (e.g. current date is 1/1/2017) Below query works for all other week except the first week of the year. However below query returns nothing for the first week of the year.
where DateDim_Date.YEAR=year(DATEADD(Day, -7, getDate()))
and DateDim_Date.WEEKNUMBER = datePart(wk,getDate())-1
Thanks in advance!
Upvotes: 1
Views: 37
Reputation: 5707
Use this:
where DateDim_Date.YEAR=year(DATEADD(MONTH, -1, getDate()))
and DateDim_Date.WEEKNUMBER = datePart(wk,DATEADD(DAY,-7,GETDATE()))
You want to get (weeknumber of (current date - 7 days)), not (weeknumber of current date) -1
Upvotes: 1