Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleCalculate the number of days in a month using DateSerial
DescriptionThis example shows how to calculate the number of days in a month using DateSerial in Visual Basic 6.
Keywordsday, month, date
CategoriesUtilities
 
Thanks to Rogério Peres.

The program gets the year and month you entered. It adds 1 to the month and uses DateSerial to get a Date representing the 0th day of the following month. That is the last day of the month you entered. The Day function gives you the number of that day, which equals the number of days in the month.

 
Private Sub cmdGo_Click()
Dim month_number As Integer
Dim year_number As Integer

    month_number = Month(txtMonth.Text)
    year_number = Year(txtMonth.Text)
    MsgBox "Days: " & Format$(Day(DateSerial(year_number, _
        month_number + 1, 0)))
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated