'********************************************************************************************************** ' Name: daysInMonth ' Author: mielk | 2012-03-11 ' ' Comment: Function to return the number of days in a specified month. ' ' Parameters: ' month A month for which the number of days is to be returned. ' If the month number is not within the range 1-12, a year counter is decremented ' or incremented while the month rolls over from 1 to 12 or from 12 to 1. ' year Optional parameter. ' Year part of a date for which the number of days is to be returned. ' If this parameter is not given, the current year is used. ' ' ' Returns: ' Byte The number of days in a specified month and year. ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2012-03-11 mielk Function created. '********************************************************************************************************** Public Function daysInMonth(month As Integer, Optional Year As Integer) As Byte Const METHOD_NAME As String = "daysInMonth" '------------------------------------------------------------------------------------------------------ Dim iYear As Integer '------------------------------------------------------------------------------------------------------ 'Variable [iYear] assumes the value of a given parameter year or the current year if ----------------| 'this parameter is omitted. '| If Year = 0 Then '| iYear = VBA.Year(VBA.Date) '| Else '| iYear = Year '| End If '| '----------------------------------------------------------------------------------------------------| daysInMonth = VBA.Day(VBA.DateSerial(iYear, month + 1, 1) - 1) End Function