Jan 28, 2010 #1 Malc8179 MIS Joined Oct 8, 2007 Messages 28 Location GB Hi Guys i have this in a bit of code DATEADD(d, - DATEPART(dw, dbo.TimeSheets.Date), DATEADD(d, 2, dbo.TimeSheets.Date)) its returning sundays as the start of a new week not the end of the week (works fine for all other days in the week) any ideas what in doing wrong
Hi Guys i have this in a bit of code DATEADD(d, - DATEPART(dw, dbo.TimeSheets.Date), DATEADD(d, 2, dbo.TimeSheets.Date)) its returning sundays as the start of a new week not the end of the week (works fine for all other days in the week) any ideas what in doing wrong
Jan 28, 2010 #2 simian336 Programmer Joined Sep 16, 2009 Messages 723 Location US Use the @@DATEFIRST function to see the current setting of SET DATEFIRST. See BOL for SET DATEFIRST to change it. Simi Upvote 0 Downvote
Use the @@DATEFIRST function to see the current setting of SET DATEFIRST. See BOL for SET DATEFIRST to change it. Simi
Jan 29, 2010 #3 Jamfool IS-IT--Management Joined Apr 10, 2003 Messages 484 Location GB Try: Code: DECLARE @TimeSheets TABLE ([Date] datetime) INSERT INTO @TimeSheets VALUES ('2010-01-29') INSERT INTO @TimeSheets VALUES ('2010-01-22') SELECT [Date], DATEADD(dd, 6 - (@@DATEFIRST + 5 + DATEPART(dw, [Date])) % 7, [Date]) SundayEOF FROM @TimeSheets Upvote 0 Downvote
Try: Code: DECLARE @TimeSheets TABLE ([Date] datetime) INSERT INTO @TimeSheets VALUES ('2010-01-29') INSERT INTO @TimeSheets VALUES ('2010-01-22') SELECT [Date], DATEADD(dd, 6 - (@@DATEFIRST + 5 + DATEPART(dw, [Date])) % 7, [Date]) SundayEOF FROM @TimeSheets