3/27/2019

Get Week End Date Using SQL Server

Below SQL code will provide End 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 so based on your start week day, end day of week will get calculated.


SET DATEFIRST 1

 
 
Declare @UpdateDate Date


Set @UpdateDate=GetDate()

 
Select


Case When DATEPART(dw,@UpdateDate) =7 then @UpdateDate

Else
Dateadd(dd,(7-DATEPART(dw,@UpdateDate)),@UpdateDate)

end as WeekEndDate

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...