Calculate Elapsed Time in Minutes (results may be negative, or past midnight)

rgsanchez

New Member
Joined
Dec 1, 2016
Messages
11
Hello,
I need to calculate how many minutes early/late a train arrived. I am comparing the scheduled train arrival, versus the actual train arrival. I have tried many formulas, but can't find a formula that works for all five scenarios I've encountered in my data below. Please note I must use the 1900 Excel date system (Windows default) and the calculated minutes early/late must remain numeric (not text), so that I can use those values in future calculations.

ScenarioScenario DescriptionScheduled
Train Arrival
Actual
Train Arrival
Current Function UsedResult
Minutes Early/Late
Desired Result?
1Train was late8:58 AM9:05 AM=IFERROR((D5-C5)*1440,"") 7.00 Yes
2Train was early5:50 PM5:48 PM=IFERROR((D6-C6)*1440,"") (2.00) Yes
3Train was exactly on-time7:07 PM7:07 PM=IFERROR((D7-C7)*1440,"") (0.00) Yes
4Train arrived after midnight.11:03 PM12:00 AM=IFERROR((D8-C8)*1440,"") (1,383.00) No (should be "57")
5Train arrived after midnight.11:03 PMmissing=IFERROR((D9-C9)*1440,"") Yes

<tbody>
</tbody>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
As 12:00AM is actually the next day (00:00 in 24 hours clock) then you really need the Scheduled and Arrival dates and the maths will work.

Scheduled Train Arrival
Actual Train Arrival​
Result​
1/1/2019 23:03​
1/2/2019 0:00​
57​

<tbody>
</tbody>
 
Upvote 0
As 12:00AM is actually the next day (00:00 in 24 hours clock) then you really need the Scheduled and Arrival dates and the maths will work.

Scheduled Train Arrival
Actual Train Arrival​
Result​
1/1/2019 23:03​
1/2/2019 0:00​
57​

<tbody>
</tbody>

Hi Toadstool,
Thank you for your response, but I am looking for a solution that does not require me to use the full dates, as that would mean I'd have to make changes to my raw data.
I did see a solution in one of the forums that solves the 'after midnight' scenario 4. However, I can't use it because the function doesn't work well for all my other scenarios. I am looking for one function that will work with all five scenarios.

Solution to 'after midnight' scenario without using full dates (posted by someone else from another forum):
B2: 23:00
C2: 1:37
D2: =C2-B2+(B2>C2)


Thank you,
Rosa
 
Upvote 0
Rosa,

There can't be a 100% solution as without the date it has to be a judgement call.

We see the midnight and judge the train must have been 57 minutes late, but what if it's actual arrival was 6:03 PM, would we say it's 18 hours and 57 minutes late or 5 hours early?

If you can make the judgement that any difference of more than 12 hours (720 minutes) probably means the start and actual times go over midnight.

I've added another scenario with a scheduled after midnight time and actual before midnight and use formula:
=IFERROR(IF((D3-C3)*1440>720,((D3-C3)*1440)-1440,IF((D3-C3)*1440<-720,((D3-C3)*1440)+1440,(D3-C3)*1440)),"")

ABCDEF
1ScenarioScenario DescriptionScheduledActualCurrent Function UsedResult
2Train ArrivalMinutes Early/Late
31Train was late8:58 AM9:05 AM77
42Train was early5:50 PM5:48 PM-2-2
53Train was exactly on-time7:07 PM7:07 PM00
64Train arrived after midnight.11:03 PM12:00 AM-138357
75Train arrived after midnight.11:03 PMmissing
86Train scheduled after midnight12:05 AM11:45 PM1420-20

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1 (2)

Worksheet Formulas
CellFormula
E3=IFERROR((D3-C3)*1440,"")
F3
=IFERROR(IF((D3-C3)*1440>720,((D3-C3)*1440)-1440,IF((D3-C3)*1440<-720,((D3-C3)*1440)+1440,(D3-C3)*1440)),"")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Rosa,

There can't be a 100% solution as without the date it has to be a judgement call.

We see the midnight and judge the train must have been 57 minutes late, but what if it's actual arrival was 6:03 PM, would we say it's 18 hours and 57 minutes late or 5 hours early?

If you can make the judgement that any difference of more than 12 hours (720 minutes) probably means the start and actual times go over midnight.

I've added another scenario with a scheduled after midnight time and actual before midnight and use formula:
=IFERROR(IF((D3-C3)*1440>720,((D3-C3)*1440)-1440,IF((D3-C3)*1440<-720,((D3-C3)*1440)+1440,(D3-C3)*1440)),"")

ABCDEF
1ScenarioScenario DescriptionScheduledActualCurrent Function UsedResult
2Train ArrivalMinutes Early/Late
31Train was late8:58 AM9:05 AM77
42Train was early5:50 PM5:48 PM-2-2
53Train was exactly on-time7:07 PM7:07 PM00
64Train arrived after midnight.11:03 PM12:00 AM-138357
75Train arrived after midnight.11:03 PMmissing
86Train scheduled after midnight12:05 AM11:45 PM1420-20

<tbody>
</tbody>
Sheet1 (2)

Worksheet Formulas
CellFormula
E3=IFERROR((D3-C3)*1440,"")
F3=IFERROR(IF((D3-C3)*1440>720,((D3-C3)*1440)-1440,IF((D3-C3)*1440<-720,((D3-C3)*1440)+1440,(D3-C3)*1440)),"")

<tbody>
</tbody>

<tbody>
</tbody>
Hi Toadstool,
Your function in F3 solved my issue! Typically a train will never be later, and definitely not earlier, than even 5 hours. Trains that are more than 3 hours late typically just get cancelled. Thank you so much for your help. I am working with a very large data set that needs regular updating. Not having to use the complete date will save me a lot of time. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,178
Members
448,871
Latest member
hengshankouniuniu

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