Menu ▼



Posted By :
avatarmrkraju
Total Views : 447

SQL Query to find last day or number of days in a month

Below query will give you the last day of the previous month.

SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m, 0, GETDATE()),0)))

Below query will give you the last day of the current month.

SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m, 0, GETDATE())+1,0)))

Below query will give you the last day of the next month.

SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m, 0, GETDATE())+2,0)))

Example






comments powered by Disqus


Search dotnetlearners.com