Below SQL code will provide Start Date of a week:
Here in below SQL code, I have used SET DATEFIRST 1 because 1 is for Start of my week is from Monday so If you want to start your week from another day of week than you can replace 1 with that particular Day number.
SET DATEFIRST 1
Declare @UpdateDate Date
Set @UpdateDate='03/12/2019'
Select
Case When DATEPART(dw,@UpdateDate) =1 then @UpdateDate
Here in below SQL code, I have used SET DATEFIRST 1 because 1 is for Start of my week is from Monday so If you want to start your week from another day of week than you can replace 1 with that particular Day number.
SET DATEFIRST 1
Else
end as WeekStartDate
Dateadd(dd,-(DATEPART(dw,@UpdateDate)-1),@UpdateDate)
No comments:
Post a Comment