Calculate time difference between two times with removing non working hours

pratik554

New Member
Joined
Apr 15, 2022
Messages
5
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
Hi All,

I have been trying to fix the issue since long time but unable to get the exact required result. My requirement is as below.

1) Need to calculate difference between 2 dates and time
2) This dates may go overnight and should exclude non working hours
3) There is non working hours from 23:00 and 1:00 AM. For example - 15th April 11:00 PM to 16th April 1:00 AM. System is no available
4) All days are working and there is no holiday

Test Data.xlsx
ABCD
1Start Date & TimeEnd Date & TimeNew Formula TATNormal TAT
201-04-2022 07:41:25 AM02-04-2022 08:0500 hrs 23 mins00 hrs 23 mins
301-04-2022 08:18:16 AM02-04-2022 08:0523 hrs 46 mins23 hrs 46 mins
401-04-2022 08:18:46 AM02-04-2022 08:0523 hrs 46 mins23 hrs 46 mins
501-04-2022 08:35:16 AM02-04-2022 08:0523 hrs 29 mins23 hrs 29 mins
601-04-2022 08:45:37 AM02-04-2022 08:0523 hrs 19 mins23 hrs 19 mins
701-04-2022 08:50:06 AM02-04-2022 08:0523 hrs 14 mins23 hrs 14 mins
801-04-2022 09:12:25 AM02-04-2022 08:0522 hrs 52 mins22 hrs 52 mins
901-04-2022 09:21:56 AM02-04-2022 08:0522 hrs 43 mins22 hrs 43 mins
1001-04-2022 09:24:45 AM02-04-2022 08:0522 hrs 40 mins22 hrs 40 mins
1101-04-2022 09:29:06 AM02-04-2022 08:0522 hrs 35 mins22 hrs 35 mins
1201-04-2022 09:30:16 AM02-04-2022 08:0522 hrs 34 mins22 hrs 34 mins
1301-04-2022 09:38:56 AM02-04-2022 08:0522 hrs 26 mins22 hrs 26 mins
1401-04-2022 09:42:06 AM02-04-2022 08:0522 hrs 22 mins22 hrs 22 mins
1501-04-2022 09:42:36 AM02-04-2022 08:0522 hrs 22 mins22 hrs 22 mins
1601-04-2022 09:49:55 AM02-04-2022 08:0522 hrs 15 mins22 hrs 15 mins
1701-04-2022 10:00:05 AM02-04-2022 08:0522 hrs 04 mins22 hrs 04 mins
1801-04-2022 10:01:06 AM02-04-2022 08:0522 hrs 03 mins22 hrs 03 mins
1901-04-2022 10:08:16 AM02-04-2022 08:0521 hrs 56 mins21 hrs 56 mins
2001-04-2022 10:10:16 AM02-04-2022 08:0521 hrs 54 mins21 hrs 54 mins
2101-04-2022 10:12:46 AM02-04-2022 08:0521 hrs 52 mins21 hrs 52 mins
2201-04-2022 10:20:02 AM02-04-2022 08:0521 hrs 45 mins21 hrs 45 mins
2301-04-2022 10:40:05 AM02-04-2022 08:0521 hrs 24 mins21 hrs 24 mins
2401-04-2022 10:41:05 AM02-04-2022 08:0521 hrs 23 mins21 hrs 23 mins
2501-04-2022 10:43:36 AM02-04-2022 08:0521 hrs 21 mins21 hrs 21 mins
2601-04-2022 10:46:15 AM02-04-2022 08:0521 hrs 18 mins21 hrs 18 mins
2701-04-2022 10:49:17 AM02-04-2022 08:0521 hrs 15 mins21 hrs 15 mins
2801-04-2022 10:49:46 AM02-04-2022 08:0521 hrs 15 mins21 hrs 15 mins
2901-04-2022 10:49:46 AM02-04-2022 08:0521 hrs 15 mins21 hrs 15 mins
3001-04-2022 11:08:36 AM02-04-2022 08:0520 hrs 56 mins20 hrs 56 mins
3101-04-2022 11:09:15 AM02-04-2022 08:0520 hrs 55 mins20 hrs 55 mins
3201-04-2022 11:12:16 AM02-04-2022 08:0520 hrs 52 mins20 hrs 52 mins
3301-04-2022 11:27:37 AM02-04-2022 08:0520 hrs 37 mins20 hrs 37 mins
3401-04-2022 11:30:47 AM02-04-2022 08:0520 hrs 34 mins20 hrs 34 mins
3501-04-2022 11:35:17 AM02-04-2022 08:0520 hrs 29 mins20 hrs 29 mins
3601-04-2022 11:39:05 AM02-04-2022 08:0520 hrs 26 mins20 hrs 26 mins
3701-04-2022 11:41:05 AM02-04-2022 08:0520 hrs 24 mins20 hrs 24 mins
3801-04-2022 11:46:37 AM02-04-2022 08:0520 hrs 18 mins20 hrs 18 mins
3901-04-2022 11:54:25 AM02-04-2022 08:0520 hrs 10 mins20 hrs 10 mins
4001-04-2022 12:00:26 PM02-04-2022 08:0520 hrs 04 mins20 hrs 04 mins
4101-04-2022 12:03:27 PM02-04-2022 08:0520 hrs 01 mins20 hrs 01 mins
4210-04-2022 11:21:39 PM10-04-2022 23:2500 hrs 03 mins00 hrs 03 mins
Data
Cell Formulas
RangeFormula
C2:C42C2=MOD(NETWORKDAYS(A2,B2,A2)*("23:00"-"01:00")-(1-MOD(B2-A2,1)),1)
D2:D42D2=B2-A2
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi All, please help in this. This will be really helpful.
 
Upvote 0
Hi All,

Please help me in resolving this
Put this formula into E2 and then copy down
Excel Formula:
=SUMPRODUCT((MOD("23:00"-"1:00",1)>MOD(A2:B2-"1:00",1))*MOD("23:00"-A2:B2,1)*{1,-1})+MOD("23:00"-"1:00",1)*((MOD(B2-A2,1)>MOD("1:00"-A2,1))+INT(B2-A2))[/CODE
 
Upvote 0
Put this formula into E2 and then copy down
Excel Formula:
=SUMPRODUCT((MOD("23:00"-"1:00",1)>MOD(A2:B2-"1:00",1))*MOD("23:00"-A2:B2,1)*{1,-1})+MOD("23:00"-"1:00",1)*((MOD(B2-A2,1)>MOD("1:00"-A2,1))+INT(B2-A2))[/CODE
Thank you for helping me in this.

I have tried the formula, however, unable to get the last 2 part of formula. What to be entered in [/CODE[/CODE].
 
Upvote 0
Thank you for helping me in this.

I have tried the formula, however, unable to get the last 2 part of formula. What to be entered in [/CODE[/CODE].
Sorry for my misstake, its exactly what below
=SUMPRODUCT((MOD("23:00"-"1:00",1)>MOD(A2:B2-"1:00",1))*MOD("23:00"-A2:B2,1)*{1,-1})+MOD("23:00"-"1:00",1)*((MOD(B2-A2,1)>MOD("1:00"-A2,1))+INT(B2-A2))
 
Upvote 0
Solution
Sorry for my misstake, its exactly what below
=SUMPRODUCT((MOD("23:00"-"1:00",1)>MOD(A2:B2-"1:00",1))*MOD("23:00"-A2:B2,1)*{1,-1})+MOD("23:00"-"1:00",1)*((MOD(B2-A2,1)>MOD("1:00"-A2,1))+INT(B2-A2))
Thank you so much!! this worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top