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

Tableau interview questions and answers for experienced professionals

  Tableau Interview Questions and Answers for experienced professional 1. What is TABLEAU? Tableau  is the powerful and fastest visualizing ...