Public Function IsValidDate(ByVal Year As UShort, ByVal Month As Byte, ByVal Day As Byte) As Boolean
' Determine whether the given date exists in the current Gregorian calendar
' Example: IsValidDate(2006, 11, 30) = True, IsValidDate(2006, 11, 31) = False
'
' Visustin sample algorithm
' ©2006 Aivosto Oy (www.aivosto.com)
If Month >= 1 And Month <= 12 Then
If Day >= 1 Then
' Compare to maximum days in this month
If Day <= DaysInMonth(Year, Month) Then
Return True ' Valid date
Else
Return False ' Day exceeds max days in month
End If
Else
Return False ' Day cannot be below 1
End If
Else
Return False ' Invalid month
End If
End Function
|