Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate days in month 1

Status
Not open for further replies.

meinhunna

Programmer
Jul 31, 2004
118
AU
how can i calculate number of days in current month using access query
 
I found this code at a site awhile ago, but I can't remember where. Anyways add this function into a module and reference it from a query.

Code:
Function GetDaysInMonth(dteInput As Date) As Integer
On Error GoTo ErrHandler
    
    Select Case Month(dteInput)
        Case 2
            GetDaysInMonth = 28
            Dim iYear As Integer
            iYear = Year(dteInput)
            If iYear Mod 4 = 0 Then
                If iYear Mod 100 = 0 Then
                    If iYear Mod 400 = 0 Then
                        GetDaysInMonth = 29
                    End If
                Else
                    GetDaysInMonth = 29
                End If
            End If
        Case 4, 6, 9, 11
            GetDaysInMonth = 30
        Case Else
            GetDaysInMonth = 31
    End Select
    
Exit Function



John Borges
 
No need for UDF:
Day(DateSerial(Year(Now),Month(Now)+1,0))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
very sneaky, phv
Hey, it's not me but VBA ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top