SQL SERVER: Get first, last date and week day name of month - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

SQL SERVER: Get first, last date and week day name of month

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.


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

Implementation:

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

 OUTPUT:
SQL SERVER: Get first and last date and week day name of month



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.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon