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

Business Days - with time

Status
Not open for further replies.

ba4crm

Technical User
Dec 19, 2003
92
US
Hello,
I have reviewed the FAQs and threads but have not been able to locate any information on how to calculate a date/time difference in business days. In other words, given two dates (formatted as mm:dd:yy hh:mm), I would like to determine the diff between two dates only counting business days and business hours (8am to 5pm).
I have used the business days calculation successfully before, but have never used the business hours/minutes.
Any thoughts?

Thank you
 
I have used this function for calculating business days (doesn't account for holidays)...

Code:
Public Function NetWorkingDays(StartDate As Date, EndDate As Date) As Integer

   Dim intCount As Integer

   intCount = 0

   Do While StartDate <= EndDate
      Select Case Weekday(StartDate)
         Case 1, 7
            intCount = intCount
         Case 2, 3, 4, 5, 6
            intCount = intCount + 1
      End Select
   
      StartDate = StartDate + 1
   Loop

   NetWorkingDays = intCount

End Function

I took that function and tweaked it a bit to calculate business minutes (counting minutes between 8am and 5pm only)...

Code:
Public Function NetBusinessMinutes(StartTime As Date, EndTime As Date) As Integer

    Dim intCount As Integer
    Dim dtmTime As Date
    
    intCount = 0
    
    Do While StartTime <= EndTime
        dtmTime = Format(StartTime, "hh:mm")
        
        If dtmTime >= #8:00:00 AM# And dtmTime <= #5:00:00 PM# Then
            intCount = intCount + 1
        End If
        
        StartTime = DateAdd("n", 1, StartTime)
        
    Loop
    
    NetBusinessMinutes = intCount
    
End Function


Code:
 
There is a faq re the more strict interpertation of business days - w/o the time issue. There is at least one thread (not faq) which does delve into the business hours. Couldn't begin to recall which forum or when, so can opnly suggest an agressive use of the advanced search engine.



MichaelRed


 
faq181-261 for the working days function Use the term "DeltDays" in advanced search and you will (should?) find a number of threads which delve into the issue of limiting to a set number of hours for the business days.

MichaelRed


 
Thank you MichaelRed. I will run the search options you recommend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top