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

Time Calculations

Status
Not open for further replies.

mousematt

MIS
Feb 5, 2001
102
GB
Hi,

First I've got to say that I hate and can't do time calculations! I am writing a basic helpdesk, fault logging site and need to set SLA times. These times have to take into account when our offices are closed and the weekend.

In the app there is a choice of SLA 1 - 4
1 being 1 hour response
2 being 4 hour response
3 being 8 hour response
4 being 48 hour response

What I need is to be able to take the date/time now and add the correct amount of time/sla, but we only work 8 - 8 so the time when there is no one here (out of office hours) needs to be added as well.

eg.
fault logged at 4pm with sla 3 will have an sla time of 12:00 the next day.

Can anyone help??

Matt
 
For the first 3 you could simply add the hours, then if the new hour for the date/time object is > 20 simply add an additional 12 hours. I'm not sure about the 4th choice simply because I don't know if it is supposed to be 2 days or you truly want 48 hours of 8-8 hours.

1-3:
Code:
Dim tm
Select Case choice
   Case "1"
      tm = DateAdd("h",1,Now)
      if Hour(tm) > 20 Then tm = DateAdd("h",12,tm)
   Case "2"
      tm = DateAdd("h",4,Now)
      if Hour(tm) > 20 Then tm = DateAdd("h",12,tm)
   Case "3"
      tm = DateAdd("h",8,Now)
      if Hour(tm) > 20 Then tm = DateAdd("h",12,tm)
   Case "4"
      'if it is truly 48 hours of work time, than we can simply add 4 days (4 days * 12 hours = 48 hours)
      tm = DateAdd("d",4,Now)
End Select

Nopw the 48 hours I used there assumes that the entry is put in during business hours (8-8). It might be safer to not assume this. If the Hour is > 20 then it should be set to 20 becaue 48 hours will end on the 4th full day.

Anyways, hope this helps,
-T


01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Good point about the 48 hours.
Have run it and have only found one thing that is a bit off. If its 20:01 - 20:59 it doesn't add the 12 hours, any ideas?

Good script though, have never used the select case before
 
Had a play:-

Dim tm
Dim dteCompare
dteCompare = CDate(Date & " 20:00:00")
Select Case choice
Case "1"
tm = DateAdd("h",1,Now)
If DateDiff("s", dteCompare, tm) >= 1 Then tm = DateAdd("h", 12, tm)
Case "2"
tm = DateAdd("h",4,Now)
If DateDiff("s", dteCompare, tm) >= 1 Then tm = DateAdd("h", 12, tm)
Case "3"
tm = DateAdd("h",8,Now)
If DateDiff("s", dteCompare, tm) >= 1 Then tm = DateAdd("h", 12, tm)
Case "4"
'if it is truly 48 hours of work time, than we can simply add 4 days (4 days * 12 hours = 48 hours)
tm = DateAdd("d",4,Now)
End Select
 
Could you not, compare the dates and see how many days there are between them. Take that number and times by 24. Then compare the time now, and the time then and do the same with that, there for you should get the correct time.

Dunno if this is any help at all.

JP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top