Search Tools Links Login

GetDaysInMonth


Visual Basic 6, or VB Classic

'This function will use the computers clock to retrive the days in any month, including leap years.
'If you use this code then please leave your comments or even vote if you have time..

Original Author: Cux

Inputs

'The are only two inputs one of which is optional.
'The First Is ValMonth which is the month you want to get the days for.
'The second is the year, if not obmited then the current year is used.

Assumptions

'This code is in a function, if you are not sure about functions then please read about them before using this code.

Returns

'The days in the month specifyed

Side Effects

'None that i know about, and there souldnt be any

Code

'Please dont remove this TAG
'By CoderUX 31-10-2002
'Copy this code into your form or module
Public Function GetDaysInMonth(ByVal ValMonth As Double, Optional ByVal ValYear As Double) as double
On Error GoTo Handler:
If ValYear = Empty Then
GetDaysInMonth = DateDiff("D", "01/" & ValMonth & "/" & Format(Now, "YYYY"), DateAdd("M", 1, "01/" & ValMonth & "/" & Format(Now, "YYYY")))
Else
GetDaysInMonth = DateDiff("D", "01/" & ValMonth & "/" & ValYear, DateAdd("M", 1, "01/" & ValMonth & "/" & ValYear))
End If
Handler:
Exit Function
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 129 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.