Click here to Skip to main content
15,891,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to find Number of Days in Sql Server for a specific date

For Example

Declare @date datetime='2012-11-25'


I have to find No. of days for @date (ie)Number of days for November month

My answer should be 30
Posted

try below code:-

SQL
SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,'2011-02-25')+1,0)))
 
Share this answer
 
v2
try the below one and pass your requried month

SELECT DATEPART(dd, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0)))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900