VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY ITS DONE.

by Robby Bassic (3 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 23rd November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY IT"S DONE.

Rate Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY ITS DONE.



    
    Dim nSunCounter As Integer      'count Sundays
    Dim nSatCounter As Integer      'count Saturdays
    Dim nWeekdayCounter As Integer  'count Weekdays
    Dim dDateStart As Date          'Starting date
    Dim dDateEnd As Date            'Ending date
    Dim nLoop As Integer            'set end point of loop
    Dim x As Integer                'for loop
    
    dDateStart = Format("01/13/2000", "mm/dd/yy")       'Assign date to start of loop
    dDateEnd = Format("1/13/2001", "mm/dd/yy")          'assign value to end of loop(this is where loop should END
    nLoop = DateDiff("d", dDateStart, dDateEnd)         'calculate how many days to loop through
    
    For x = 0 To nLoop                                  'loop those many days
        If Weekday(dDateStart) = vbSaturday Then        '(Check if Sat)
            nSatCounter = nSatCounter + 1               'count Sat
        ElseIf Weekday(dDateStart) = vbSunday Then      'Check if Sun
            nSunCounter = nSunCounter + 1               'Count Sun
        Else
            nWeekdayCounter = nWeekdayCounter + 1       'Count Weekdays
        End If
        dDateStart = dDateStart + 1                     'increment 1 day at a time (For loop ONLY)
    Next x
    
    MsgBox "Weekdays: " & nWeekdayCounter & " Sat: " & nSatCounter & " Sun: " & nSunCounter
    
End Sub



Download this snippet    Add to My Saved Code

Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY ITS DONE. Comments

No comments have been posted about Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY ITS DONE.. Why not be the first to post a comment about Calculate how many WeekDays or WeekEnds are between two dates. THIS IS THE WAY ITS DONE..

Post your comment

Subject:
Message:
0/1000 characters