I need to add SQL into a report query that returns the date of the previous Wednesday and the date of the current week Tuesday.
I've been able to get the previous week Tuesday to current week Monday with this:
DATEDIFF(wk,DATEDIFF(wk,7,GETDATE()),1)
DATEDIFF(wk,DATEDIFF(wk,7,GETDATE()),7)
I tried tweaking the numbers from above, but no dice. Not sure if it's because today is the “current Tuesday” so it can’t calculate it, and maybe I just need to try tomorrow.
2条答案
按热度按时间dy1byipe1#
output:
see: DBFIDDLE
3-DATEPART(weekday,GETDATE())
will get you 0 days added to the current date.3-4
, so subtract 1 from the date of tomorrow, which again should be a Tuesday.ejk8hzay2#
With a little help from date arithmetic, we get the following solution.
Result.
SQL Fiddle.