Sql server: Get number of days in current month - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Sql server: Get number of days in current month

In this article I am going to explain how to get the number of days in current month in Sql server.


Implementation:

To get the number of days in current in month run the below given query in Sql server:

declare @currentdate datetime
set @currentdate = getdate()
SELECT DATEPART(day, DATEADD(s,-1,DATEADD(month, DATEDIFF(month,0,@currentdate)+1,0))) as NumberOfDaysInMonth

OR

declare @currentdate datetime
set @currentdate = getdate()

SELECT DAY(DATEADD(day,-1,DATEADD(month, DATEDIFF(month, 0, @currentdate) + 1, 0))) as NumberOfDaysInMonth

Result :
Sql server: Get number of days in current 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.


EmoticonEmoticon