Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL-ServerSQL2008
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 28 Dec '12 - 18:07


2 solutions

try below code:-
 
SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,'2011-02-25')+1,0)))
  Permalink  
try the below one and pass your requried month
 
SELECT DATEPART(dd, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0)))
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 206
1 Sergey Alexandrovich Kryukov 175
2 Richard MacCutchan 145
3 Tadit Dash 140
4 Santhosh G_ 125
0 Sergey Alexandrovich Kryukov 10,294
1 OriginalGriff 7,955
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid