3/26/2019

Get Week Start Date in SQL Server with example

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
Else
Dateadd(dd,-(DATEPART(dw,@UpdateDate)-1),@UpdateDate)


end as WeekStartDate
 

No comments:

Post a Comment

Power BI Interview Questions and Answers

Power BI Interview Questions For Freshers The rising need for organizations to make decisions based on data has increased the demand for c...