13 June 2013

How to Find Total Number of Days in a Month in SQL Server

To get total number of days in a month we need to write the query like as shown below


DECLARE @sample datetime
SET @sample=GETDATE()  -- Sample date
select datediff(dd,dateadd(dd, 1-day(@sample),@sample), dateadd(m,1,dateadd(dd, 1-day(@sample),@sample)))
By using above query we can get total number of days for particular month.

No comments:

Post a Comment