# question

## sql for day of the week in the future

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.
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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

·
all of the time - so it should not matter if it's thur or friday at the time the query id executed, tue should be the return date.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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)

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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)

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.