Monday, June 20, 2016

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

No comments:

Post a Comment