Days in month

  • Thread starter Thread starter Chris Nebinger
  • Start date Start date
C

Chris Nebinger

Not a built in, but the UDF is pretty simple:

Function DaysInMonth(dteDay) As Integer
Dim dteTemp As Date
'Get the first day of the current month
dteTemp = DateSerial(Year(dteDay), Month(dteDay), 1)
'Add 1 month
dteTemp = DateAdd("m", 1, dteTemp)
'Subtract 1 day to get last day of previous month
dteTemp = dteTemp - 1
'Number of days in the month is the day part
DaysInMonth = Day(dteTemp)
End Function


Call it like: DaysInMonth(Now)


Chris Nebinger
 
Thanks guys,
that works perfect !!!
-----Original Message-----
Not a built in, but the UDF is pretty simple:

Function DaysInMonth(dteDay) As Integer
Dim dteTemp As Date
'Get the first day of the current month
dteTemp = DateSerial(Year(dteDay), Month(dteDay), 1)
'Add 1 month
dteTemp = DateAdd("m", 1, dteTemp)
'Subtract 1 day to get last day of previous month
dteTemp = dteTemp - 1
'Number of days in the month is the day part
DaysInMonth = Day(dteTemp)
End Function


Call it like: DaysInMonth(Now)


Chris Nebinger

.
 
Back
Top