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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find out how many monday between two dates

Status
Not open for further replies.

dorling

Technical User
Mar 25, 2004
80
GB
i basic need to find out how many monday (or tueday etc) there as been in between two date.

for example

12/08/04 to the 16/09/04 there was 5 monday.

the date are in a table and i need the number of monday(or tueday) in VBA String

thanks in advance

Jonathan D
 
Code:
Public Function basCntofDOW(dtStrt As Date, dtEnd As Date, DOW As Integer) As Integer

    'Purpose:   Count the number of occurances or the specified Day of hte Wook between Dates
    '12/08/04 to the 16/09/04 there was 5 monday
    
    'Michael Red 8/26/04
    'Sample Usage   - Please Note the "US" Standard date format
    '? basCntofDOW(#8/12/04#, #9/16/04#, vbMonday) _
     5


    Dim FirstDOW As Date

    If (DOW < vbSunday Or DOW > vbSaturday) Then
        basCntofDOW = 0
        GoTo ExitNoDOW
    End If

    If (dtStrt >= dtEnd) Then
        basCntofDOW = 0
        GoTo ExitNoDOW
    End If

    FirstDOW = DateAdd("d", 7 + DOW - Weekday(dtStrt), dtStrt)
    basCntofDOW = (Int((dtEnd - FirstDOW) / 7)) + 1

NormExit:
    Exit Function

ExitNoDOW:
'    Insert error stuff Here

End Function


MichaelRed
mlred@verizon.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top