Alex Rivera | Logout

SQL: how to get sunday of current week

Asked 2012-07-20T13:55:23.913
16

I want to get the last day( Sunday) of current week given any timestamp. I tried following script, but it returns Saturday as the last day rather than Sunday as I expected.

Select DATEADD(DAY , 7-DATEPART(WEEKDAY,GETDATE()),GETDATE()) AS 'Last Day Of Week' 

Any answer is welcomed!!

Edit
Report

1 Answer

20

It will work if you change the standard DATEFIRST from Sunday (7) to Monday (1):

SET DATEFIRST 1

Select DATEADD(DAY , 7-DATEPART(WEEKDAY,GETDATE()),GETDATE()) AS 'Last Day Of Week' 
answered 2012-07-20T13:59:38.933

Your Answer