SQL SERVER Query to get first and last date with week day name of month

In this article I am going to explain how to get first and last date with week day name of month in Sql Server.


Implementation:

Run the below given Sql server query to Get Week day name and date of month.

Declare @CurrentDate DATE,@FirstDay DATE,@LastDay DATE
Set @CurrentDate = getdate()
Set @FirstDay=(SELECT DATEADD(dd ,-(DAY(@CurrentDate )-1),@CurrentDate ))
Set @LastDay=(SELECT  DATEADD(dd ,-(DAY(@CurrentDate )), DATEADD(MONTH,1,@CurrentDate )))

SELECT [Week Day on First Date]=datename(dw,@FirstDay)
,[First Date of Month] = @FirstDay
,[Week day on Last date]=datename(dw,@LastDay)
,[Last Date of Month]=@LastDay

 Result:
SQL SERVER Query to get first and last date with week day name of month



Post a Comment

0 Comments