Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Weekending

Status
Not open for further replies.

Malc8179

MIS
Oct 8, 2007
28
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
 
Use the @@DATEFIRST function to see the current setting of SET DATEFIRST.

See BOL for SET DATEFIRST to change it.

Simi
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top