Results 1 to 1 of 1

Thread: VB - Find weekdays between 2 dates

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    VB - Find workdays between 2 dates

    Usually this is done with loops, but not anymore
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim EndDate As Date, StartDate As Date
    3.    
    4.     StartDate = #2/23/2006#
    5.     EndDate = #2/28/2006#
    6.    
    7.     Debug.Print FindWorkDays(StartDate, EndDate)
    8. End Sub
    9.  
    10. Private Function FindWorkDays(ByVal StartDate As Date, ByVal EndDate As Date) As Long
    11.     '
    12.     '  Made by Michael Ciurescu (CVMichael from vbforums.com)
    13.     '  Original Thread: [url]http://www.vbforums.com/showthread.php?t=390857[/url]
    14.     '
    15.     If StartDate > EndDate Then
    16.         FindWorkDays = -1
    17.     Else
    18.         FindWorkDays = Fix(EndDate - StartDate) - Fix(Fix(EndDate - DateAdd("d", -Weekday(StartDate) + 2, StartDate)) / 7) * 2
    19.     End If
    20. End Function
    Last edited by CVMichael; Apr 23rd, 2008 at 07:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width