C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to find the number of days in a month


Posted Date: 03 Jan 2007    Resource Type: Articles    Category: Databases

Posted By: Vadivel Mohanakrishnan       Member Level: Diamond
Rating:     Points: 10



Introduction



This seems to be one another frequently asked question in the discussion forums. So thought would write a small article on this today.

Basic Solution



With the help of built in SQL Server functions we can easily achieve this in one single T-SQL statement as shown below.

Select Day(DateAdd(Month, 1, '01/01/2007') - Day(DateAdd(Month, 1, '02/01/2007')))

Generalized Solution:



We can generalize it by creating a "User defined Stored Procedure" as shown below:



Create Function NumDaysInMonth (@dtDate datetime) returns int
as
Begin
Return
(
Select Day(DateAdd(Month, 1, @dtDate) - Day(DateAdd(Month, 1, @dtDate)))
)
End
Go



Test:





Select dbo.NumDaysInMonth('20070201')
Go






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Find tables which doesn't have Primary Key ...
Previous Resource: provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween masks

Contact Us    Privacy Policy    Terms Of Use