## Average time elapsed in hh:mm format between 2 dates after accounting for weekends and business hours

Hi

I have a ticket resolution data as shown below. I would need this data to monitor my SLA compliance.

Excel 2007 32 bit
A B C D E F
2 Ticket Assigned Date Acknowledged Date Resolved Date Time Elapsed (Assigned To Acknowledged) Time Elapsed (Assigned to Resolved)
3 Ticket 1 03-08-2017 21:06 04-08-2017 15:16 07-08-2017 18:29
4 Ticket 2 04-08-2017 15:03 07-08-2017 16:27 09-08-2017 23:00
5 Ticket 3 14-09-2017 00:51 14-09-2017 00:51 16-09-2017 08:51
Ticket Sheet

I have a few set of conditions, which I would want to build into my time elapsed formula -
1. If the ticket assigned date is before 8.30 AM that day (i.e. for example Ticket 3 was assigned at 00:31) the formula should consider assigned time by default as 8.30 AM on that day itself. In my ticket 3 example, the new assigned date would be 14-09-2017 08:30. Time elapsed should be calculated using this date and time.

2. If the ticket assigned date is after 5.30 PM that day (i.e. Ticket 1 in my example) the formula should consider assigned time by default as 8.30 AM on the next working day. In my ticket 1 example, the new assigned date would be 04-08-2017 08:30. Suppose the next day is a weekend (Sat and Sun are weekends) then new date would be 06-08-2017 08:30.

3. When calculating Time elapsed (both acknowledged and resolved) it would need the unit to be in HH:MM format.

4. The time elapsed should be calculated after removing the weekends and non business hours, if any. i.e in Ticket 2 example, the assigned date (04-08-2017) is a Friday and the Acknowledged and Resolved dates are Monday and Wednesday respectively. So time elapsed in this case should be the hours between these dates after removing the weekends and non-business hours within the week days.

Business Hours are - 8.30 AM to 5.30 PM and Business days are Monday to Friday.

This would be a typical support call scenario for calculating SLAs.
I had tried accounting for the business hours by the below logic.

Excel 2007 32 bit
A B C D E F
27 Assigned Date Time After 8.30 AM Before 5.30 PM New Assigned Date
28 03-08-2017 21:06 03-08-2017 9:06 PM Yes No 04-08-2017 08:30:00
29 14-09-2017 00:51 14-09-2017 12:51 AM No Yes 14-09-2017 08:30:00
Ticket Sheet

Worksheet Formulas
Cell Formula
D28 =IF([COLOR=rgb(255]C28>TIME(8,30,0),"Yes","No"[/COLOR])
E28 =IF([COLOR=rgb(255]C28
F28 =IF([COLOR=rgb(255]D28="Yes",IF(E28="No",TEXT([COLOR=0)]B28+1,"dd-mm-yyyy"[/COLOR])&" "&TEXT([COLOR=0)]TIME([COLOR=rgb(0]8,30,0[/COLOR]),"hh:mm:ss"[/COLOR]),A28),TEXT(B28,"dd-mm-yyyy")&" "&TEXT(TIME([COLOR=0)]8,30,0[/COLOR]),"hh:mm:ss")[/COLOR])
D29 =IF([COLOR=rgb(255]C29>TIME(8,30,0),"Yes","No"[/COLOR])
E29 =IF([COLOR=rgb(255]C29
F29 =IF([COLOR=rgb(255]D29="Yes",IF(E29="No",TEXT([COLOR=0)]B29+1,"dd-mm-yyyy"[/COLOR])&" "&TEXT([COLOR=0)]TIME([COLOR=rgb(0]8,30,0[/COLOR]),"hh:mm:ss"[/COLOR]),A29),TEXT(B29,"dd-mm-yyyy")&" "&TEXT(TIME([COLOR=0)]8,30,0[/COLOR]),"hh:mm:ss")[/COLOR])

But when taking the elapsed time using the newly derived assigned dates, excel only calculates difference between these dates with an assumption that both times are in a single day. I guess excel does not look into the difference in dates. Also I am not sure how I can account for the weekends in the above logic.

Would be really helpful if some one could suggest some logic to calculate the elapsed time incorporating for my conditions.

Thanks.