VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



GetDaysInMonth

by Cux (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

'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..

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.
Assumes
'This code is in a function, if you are not sure about functions then please read about them before using this code.
Code Returns
'The days in the month specifyed
Side Effects
'None that i know about, and there souldnt be any

Rate GetDaysInMonth

'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

Download this snippet    Add to My Saved Code

GetDaysInMonth Comments

No comments have been posted about GetDaysInMonth. Why not be the first to post a comment about GetDaysInMonth.

Post your comment

Subject:
Message:
0/1000 characters