VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Function that returns the number of working days between two dates

by Laura Naftanaila (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 22nd January 2009
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Function that returns the number of working days between two dates

Rate Function that returns the number of working days between two dates



Private Function WorkDays(ByVal dtBegin As Date, ByVal dtEnd As Date) As Long

   Dim dtFirstSunday As Date
   Dim dtLastSaturday As Date
   Dim lngWorkDays As Long

   dtFirstSunday = dtBegin + ((8 - Weekday(dtBegin)) Mod 7)
   dtLastSaturday = dtEnd - (Weekday(dtEnd) Mod 7)
   lngWorkDays = (((dtLastSaturday - dtFirstSunday) + 1) / 7) * 5

   If dtFirstSunday <> dtBegin Then
   lngWorkDays = lngWorkDays + (7 - Weekday(dtBegin))
   End If

   If dtLastSaturday <> dtEnd Then
      lngWorkDays = lngWorkDays + (Weekday(dtEnd) - 1)
   End If

   WorkDays = lngWorkDays

End Function


Download this snippet    Add to My Saved Code

Function that returns the number of working days between two dates Comments

No comments have been posted about Function that returns the number of working days between two dates. Why not be the first to post a comment about Function that returns the number of working days between two dates.

Post your comment

Subject:
Message:
0/1000 characters