Hi, I have a team of staff that manage a help desk. The hours are from 8:00 am to 5:00 pm. I would like to measure the response time, meaning the amount of time that it takes from when a ticket is assigned to our workgroup to when the ticket is acknowledged.
Here's the code I borrowed from another thread, but the calculations aren't accurate.
For example
OpenDate is 8/1/13 7:48 AM
AcknowledgedByTechTime is 08/01/2013 9:33:50 AM
The result is 1 hrs 45 min, but the correct result should be 1 hrs 33 min
I do not want to count the time prior to 8:00 am or after 5:00 pm.
Code:
Public Function WorkingHrsMins(OpenDate As Date, AcknowledgedByTechTime As Date) As String
'....................................................................
' Name: WorkingHrs
' Inputs: StartDate As Date & time
' EndDate As Date & time
' Returns: Integer - number of hours not inclusive of weekends
' Author: Arvin Meyer
' Date: February 19, 1997
' Modified by Steve S (ssanfu)
' Date: April 11, 2012
' Comment: Accepts two dates and returns the number
' of work hours and minutes between 8am and 5pm
' Note that this function does not account for holidays.
'....................................................................
On Error GoTo Err_WorkingHrs
Const cBeginingTime As Date = #8:00:00 AM#
Const cEndingTime As Date = #5:00:00 PM#
Dim intCountDays As Integer
Dim intHours As Integer
Dim intMinutes As Integer
Dim intTotalMin As Integer
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date
Dim tmStart As Date
Dim tmEnd As Date
intMinutes = 0
intHours = 0
intCountDays = 0
intTotalMin = 0
WorkingHrsMins = 0
'check end date > start date
If AcknowledgedByTechTime < OpenDate Then
dtTemp = OpenDate
OpenDate = AcknowledgedByTechTime
AcknowledgedByTechTime = dtTemp
End If
'get just the date portion
dtStart = Int(OpenDate)
dtEnd = Int(AcknowledgedByTechTime)
'get just the time portion
tmStart = OpenDate - dtStart
tmEnd = AcknowledgedByTechTime - dtEnd
If dtStart = dtEnd Then
intTotalMin = DateDiff("n", tmStart, tmEnd)
Else
'skip the first day
dtStart = dtStart + 1
Do While dtStart < dtEnd
'Make the above < and not <= to not count the EndDate
Select Case Weekday(dtStart)
Case Is = 1, 7
'do nothing
Case Is = 2, 3, 4, 5, 6
intCountDays = intCountDays + 1
End Select
dtStart = dtStart + 1
Loop
intTotalMin = intCountDays * 720
'first day minutes
intTotalMin = IIf(intTotalMin + DateDiff("n", tmStart, cEndingTime) < 0, 0, intTotalMin + DateDiff("n", tmStart, cEndingTime))
'Last day minutes
intTotalMin = IIf(intTotalMin + DateDiff("n", cBeginingTime, tmEnd) < 0, 0, intTotalMin + DateDiff("n", cBeginingTime, tmEnd))
End If
intHours = intTotalMin \ 60 'hours
intMinutes = intTotalMin Mod 60 'minutes
'return value
WorkingHrsMins = intHours & " hrs " & intMinutes & " min"
Exit_WorkingHrs:
Exit Function
Err_WorkingHrs:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingHrs
End Select
End Function
