In this article I am going to explain how to get first, last date and week day name of month with number of days in Sql Server.
In the previous article I have explained how to detect the leap year in Sql server, how to get first and last date of year, count total number of days in year inSql server, how to get list of all month’s name in Sql server and how to getyear calendar with months name and number of days in sql server.
Recently I have got a requirement to get first and last date with week day name of month. I am going to share this in tutorial.
Run the below given Sql server query to Get Week day name and date of month.
Declare @CurrentDate datetime,@FirstDay datetime,@LastDay datetime, @totaldays int
Set @CurrentDate = getdate()
Set @FirstDay=(SELECT DATEADD(dd ,-(DAY(@CurrentDate )-1),@CurrentDate ))
Set @LastDay=(SELECT DATEADD(dd ,-(DAY(@CurrentDate )), DATEADD(MONTH,1,@CurrentDate )))
set @totaldays = (datediff(dd,@FirstDay,@LastDay))+1
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
,[Total Number of days]= @totaldays
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.