Days In Month
This algorithm finds the total days in a month according to the input date.
Public Shared Function GetDaysInMonth(year As UInteger, month As Byte) As Byte
Dim daysInMonth As Byte
If month = 4 OrElse month = 6 OrElse month = 9 OrElse month = 11 Then
daysInMonth = 30
ElseIf month = 2 Then
If IsLeapYear(year) Then
daysInMonth = 29
Else
daysInMonth = 28
End If
Else
daysInMonth = 31
End If
Return daysInMonth
End Function
Private Shared Function IsLeapYear(year As UInteger) As Boolean
Return (year Mod 4 = 0 AndAlso (year Mod 100 <> 0 OrElse year Mod 400 = 0))
End Function
Example
Dim value = GetDaysInMonth(2015, 8)
Output
31