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

Countrdown

Status
Not open for further replies.

ukwebsite

Programmer
Dec 9, 2000
82
GB
Can someone help me again please?

Im creating an intranet page to see our support calls queue.

I can see the time that the call was created such as 22/07/2004 11.41. I have done at DateDiff against the current time to find out how many minutes has passed since the call was started.

I want to display this information in HH:MM format.

But I want the hours passed to stop at 17:00hrs and reset at 8:00hrs as this time is not calculated againt our SLA.

I then want to display how much time is left before the call goes out of SLA, we have an 8 hour SLA.

I know that im asking a lot here but i have been stuck on this for the last few days and just wondered if there is an easy way to do this.

Thanks

Matthew Wilde
matthew@ukwebsite.com
 
So you basically want a DateDiff that only counts work hours?
Hmm...

How About
Code:
<%
'Function to find elapsed time during work days
Function GetElapsedTime(startDate,endDate)
   Dim temp_date
   Dim t_minutes

   'check end date time and if the time is greater than 1700 reset it
   If TimeValue(endDate) > #17:00# Then endDate = DateValue(endDate) + #17:00#

   'check start date and if less than 8:00AM reset it
   If TimeValue(startDate) < #08:00# Then startDate = DateValue(startDate) + #08:00#

   'If the days are the same, return the diff
   If FormatDateTime(startDate,2) = FormatDateTime(endDate,2) Then
      GetElapsedTime = CMinToHour(DateDiff("n",startDate,endDate))
   Else
      'otherwise break it down into three sections: first day, intermediary days, last day

	  'First Day: DateDiff with 1700 for the number of minutes
	  temp_date = DateValue(startDate) + #17:00#
	  t_minutes = DateDiff("n",startDate,temp_date)

	  'Middle Day(s): Calculate number of days between the two dates and multiply by number of minutes in work day (9 * 60)
      t_minutes = t_minutes + (DateDiff("d",startDate,endDate) - 1) * 540

	  'End Day: Calculate Diff between 8am and now
	  temp_date = DateValue(endDate) + #08:00#
	  t_minutes = t_minutes + DateDiff("n",temp_date,endDate)

	  'return the minutes and hours string
      GetElapsedTime = CMinToHour(t_minutes)
   End If
End Function

'Function to convert a number of minutes to h:mm format
Function CMinToHour(numMinutes)
   Dim t_hours, t_minutes
   t_hours = Fix(numMinutes/60)
   t_minutes = numMinutes mod 60

   if t_minutes < 10 Then t_minutes = "0" & t_minutes

   CMinToHour = t_hours & ":" & t_minutes
End Function

'---- Sample using above functions

Dim arr_test, a_date, a_start_date
arr_test = Array(#7/23/04 10:05 AM#,#7/23/04 17:00#,#7/23/04 20:05#,#7/24/04 13:21#,#7/25/04 13:21#,#7/26/04 13:21#,#7/26/04 19:32#)
a_start_date = #7/23/04 10:00#

Response.Write "<table border=1><tr><th>Start Date</th><th>Pretend Current Date</th><th>Elapsed</th></tr>"
For Each a_date in arr_test
   Response.Write "<tr><td>" & a_start_date & "</td><td>" & a_date & "</td><td>" & GetElapsedTime(a_start_date,a_date) & "</td></tr>"
Next
Response.Write "</table>"
%>

ok, that how about took 20 minutes :p I did test it, feel free to play with it. In your usage I would expect you would make the call like:
Response.Write GetElapsedTime(someStartTime,Now)
to get the elapsed time from when the call started. i included the end date to make it easier to test.

Hope you didn't want saturdays and sundays off, that will make things a little more complicate for the "Middle Day(s)" section. My suggestion would be to leave that as is, then subtract saturdays and sundays if necessary.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top