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