- Home /

I need to script and find the date for tuesday - or dw = 3 when today is thursday...or friday...
but i need to use the tue date as a constant value to place in a report that will be used for an order date.

Comment

So are you wanting a query that will, in effect, return "Next Tuesday's date"?

**Answer** by Squirrel
·
Oct 16, 2011 at 07:16 PM

simplest way without complicated arithmetic operations is
declare @dte date
select @dte = '2011-10-17'
select dateadd(day,
case datename(weekday, @dte)
when 'Sunday' then 2
when 'Monday' then 1
when 'Tuesday' then 7
when 'Wednesday' then 6
when 'Thursday' then 5
when 'Friday' then 4
when 'Saturday' then 3
end,
@dte)

**Answer** by Magnus Ahlkvist
·
Oct 16, 2011 at 10:53 PM

SET DATEFIRST 1
DECLARE @dt DATE
SET @dt = '2011-05-13'
SELECT DATEADD(day,
CASE
WHEN datepart(weekday,@dt)<2
THEN 2-datepart(weekday,@dt)
ELSE 9-datepart(weekday,@dt)
END,
@dt)

**Answer** by DannyC
·
Aug 22, 2013 at 12:46 AM

I know this is very late, but I was looking for the same answer today and found this: select getdate(),dateadd(week, datediff(week, 0, getdate()), 9) I am including GetDate() in the results only to prove that if GetDate() changes, the returned value will always be next Wednesday (in this example). Change the 9 to an 8 for Tuesday.

Copyright 2019 Redgate Software. Privacy Policy

- Anonymous
- Sign in
- Create
- Ask a question
- Spaces
- Ask SSC Site Issues (meta-askssc)
- Explore
- Topics
- Questions
- Users
- Badges