.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

How to find number of days present in a month?

Posted By: Syed Shakeer Hussain     Posted Date: September 01, 2009    Points:2   Category :Sql Server
How to find number of days present in a month?.

Example:1/09/2009 or 1/sep/2009
I want output:30 (days)

Author: Amit Mehra             
Posted Date: September 01, 2009     Points: 5   

Hi Syed.

Here is your SQL query to find the number of days in a month

SELECT DAY(DATEADD (month, 1, DATEADD (day, 1 - DAY('1/1/2009'), '1/1/2009')) - 1)

as you know that sql server default date format is MM/dd/YYYY so you can do some date manipulation for dd/MM/YYYY but the logic will be the same.

Please "Mark As Answer " if this post help you.
Author: Appu & Pappu             
Posted Date: January 22, 2010     Points: 5   

select datepart(d,dateadd(d,-1,dateadd(m,1,dateadd(d,-datepart(d,getdate())+1,getdate()))))

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend