简体   繁体   中英

Time elapsed between two dates (in "working hours")

I must calculate in Excel the time that a Tech Support takes to resolve a problem, in his working hours.

Example :

Ticket created at : 04:00 PM the Friday 3 June 2022

Ticket resolved at : 10:00 AM the Monday 6 June 2022

Working hours : 09:00 AM to 12:00, and 01:30 PM to 06:00 PM

So the result will be : He took 3 hours to resolve the problem.

I'm open to any formula, even in VBA :)

Thanks.

EDIT 1 :

I'm using this formula currently :

=IF((NETWORKDAYS(D2;E2;PublicHolidays)-1)*(Working_Hours!$B$3-Working_Hours!$B$2)
+IF(NETWORKDAYS(D2;E2;PublicHolidays);MEDIAN(MOD(E2;1);Working_Hours!$B$3;Working_Hours!$B$2);Working_Hours!$B$3)
-MEDIAN(NETWORKDAYS(D2;E2;PublicHolidays)*MOD(D2;1);Working_Hours!$B$3;Working_Hours!$B$2)
+(NETWORKDAYS(D2;E2;PublicHolidays)-1)*(Working_Hours!$E$3-Working_Hours!$E$2)
+IF(NETWORKDAYS(D2;E2;PublicHolidays);MEDIAN(MOD(E2;1);Working_Hours!$E$3;Working_Hours!$E$2);Working_Hours!$E$3)
-MEDIAN(NETWORKDAYS(D2;E2;PublicHolidays)*MOD(D2;1);Working_Hours!$E$3;Working_Hours!$E$2)<0;0;(NETWORKDAYS(D2;E2;PublicHolidays)-1)*(Working_Hours!$B$3-Working_Hours!$B$2)
+IF(NETWORKDAYS(D2;E2;PublicHolidays);MEDIAN(MOD(E2;1);Working_Hours!$B$3;Working_Hours!$B$2);Working_Hours!$B$3)
-MEDIAN(NETWORKDAYS(D2;E2;PublicHolidays)*MOD(D2;1);Working_Hours!$B$3;Working_Hours!$B$2)
+(NETWORKDAYS(D2;E2;PublicHolidays)-1)*(Working_Hours!$E$3-Working_Hours!$E$2)
+IF(NETWORKDAYS(D2;E2;PublicHolidays);MEDIAN(MOD(E2;1);Working_Hours!$E$3;Working_Hours!$E$2);Working_Hours!$E$3)
-MEDIAN(NETWORKDAYS(D2;E2;PublicHolidays)*MOD(D2;1);Working_Hours!$E$3;Working_Hours!$E$2))

Well, this is a start, but you need to think about how to deal with multiple days etc:

在此处输入图像描述

All the example times shown are formatted as dd.mm.yy hh:mm, even consider putting the Day start & end as just the hour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM