Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

The number of days in a month

Total Hit ( 2631)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You need just one-line function to evaluate the number of days in a month (while taking leap years into account, of course). The trick is to use the DateDiff and DateSerial functions to calculate the difference between the first day of the current month and the first day of the subsequent month :

Click here to copy the following block
Function DaysInMonth(ByVal Month As Integer, ByVal Year As Integer) As Integer
  DaysInMonth = DateDiff("d", DateSerial(Year, Month, 1), DateSerial(Year, _
    Month + 1, 1))
End Function

At first it seems that you need an If statement to deal with December in a separate block of code, but the DateSerial function returns a consistent value even when Month > 12.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.