|
|
Title | Calculate the number of days in a month using DateSerial |
Description | This example shows how to calculate the number of days in a month using DateSerial in Visual Basic 6. |
Keywords | day, month, date |
Categories | Utilities |
|
|
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
|
|
|
|
|
|