Enter the start and end times. If the span crosses into another day, also enter the start and end dates (for times on the same day, you can leave the dates blank).
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formula
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Enter two times, such as 8:30 to 17:30, and you get the elapsed time between them in hours, minutes and seconds (here, 9 h) right away
- Add a start date and an end date, and spans that cross into other days, such as July 10 at 22:00 to July 12 at 6:30, are shown as "1 d 8 h 30 min" (leap years included)
- The result also shows the same span as total hours (a decimal, such as 32.5 h), total minutes and total seconds
- If the dates are blank and the end time is earlier than the start time, the start is treated as the day before, so spans over midnight work too
- A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
What is this calculation used for?
An overnight bus that leaves at 10:00 PM and arrives at 6:30 the next morning takes \(23400 - 79200 + 86400 = 30600\) seconds = 8 hours 30 minutes, even though the date changes on the way.
Knowing the travel time makes a big difference when you estimate how long you can sleep on board or plan what to do after you arrive. Even when a schedule does not list the travel time, as with local lines or connections, you can work it out yourself from the departure and arrival times.
If you go to bed at 11:30 PM and get up at 6:15 AM, you slept 6 hours 45 minutes. Because the span goes over midnight, the calculation that treats the start as the day before (adding 86400 seconds) works as is.
Sleep time is one of the most basic health records. Write down when you go to bed and when you get up each day, and you can use this subtraction to find, for example, how many hours you slept on average this week.
A runner who starts a marathon at 9:00 and finishes at 13:57 has a time of 4 hours 57 minutes. Even if you forget your stopwatch, you can find the elapsed time by subtraction as long as you know the start and finish times.
Timing in track, swimming, cycling and other sports is exactly this: the difference between two times. Handling borrowing in base 60 for minutes and seconds correctly is the basis for comparing results accurately.
If you study from 7:15 PM to 9:45 PM, that is 2 hours 30 minutes of study for the day. Write down the start and end times, and you can add up each day's total later with this same subtraction.
Study logs for an exam, time logs for remote work, and more: turning "from when to when" into "how many hours" is something you do almost every day.
"How many hours are there from 18:00 on July 10 until a 9:00 AM deadline on July 12?" With 2 days between the dates, \(86400 \times 2 + 32400 - 64800 = 140400\) seconds = 39 hours (1 day and 15 hours).
Thinking of the time left in hours makes a work plan much more realistic than a vague feeling of "I still have 2 days". Countdowns to a rocket launch or an exam are the same kind of time difference across dates.
Formula
Symbols and terms
Symbols
| \(h\), \(m\), \(s\) | h, m, s | The hour (\(h\)), minute (\(m\)) and second (\(s\)) of a time of day, on the 24-hour clock (example: for 5:30 PM, \(h = 17\), \(m = 30\) and \(s = 0\)). They stand for "hour", "minute" and "second". |
| \(T\) | T | A time of day turned into seconds after midnight, found with \(T = 3600h + 60m + s\). (Example - 17:30:00 → 63000 seconds) |
| \(T_1\), \(T_2\) | T sub 1, T sub 2 | The start time in seconds (\(T_1\)) and the end time in seconds (\(T_2\)). (Example - 8:30:00 → \(T_1 = 30600\), 17:30:00 → \(T_2 = 63000\)) |
| \(h_1, m_1\), \(h_2, m_2\) | h sub 1, m sub 1, h sub 2, m sub 2 | The hour and minute of the start time (subscript 1) and of the end time (subscript 2), used in the subtract-by-hand formula. |
| \(D\) | D | The elapsed time (how long it is from start to end). D stands for "duration". The calculator on this page finds it in seconds first, then shows it as "9 h" or "3 h 59 min". |
| \(n\) | n | The number of days from the start date to the end date, counting only the dates on the calendar. (Example - July 10 → July 12 gives \(n = 2\)) |
| \(3600\), \(86400\) | three thousand six hundred, eighty-six thousand four hundred | The seconds in 1 hour (\(60 \times 60 = 3600\)) and the seconds in 1 day (\(24 \times 3600 = 86400\)). |
Terms
| time of day | A point in time, such as 8:30. It is different from a length of time, such as 9 hours. This page finds the length of time between two times of day (the elapsed time). |
| length of time | How long something lasts, such as 9 hours. It is different from a time of day, such as 8:30. This page finds the length of time between two times of day (the elapsed time). |
| elapsed time | The length of time that passes from the start time to the end time. It is the answer this page finds. |
| 24-hour clock | A way of writing times of day with hours from 0 to 23, sometimes called military time in the US. Add 12 to PM hours (5:30 PM → 17:30, 10:00 PM → 22:00). Midnight is 0:00, and noon stays 12:00. |
| base 60 | Counting in groups of 60, where 60 of one unit make 1 of the next unit up. Sixty seconds make 1 minute and 60 minutes make 1 hour. It is easy to make mistakes when this is mixed with ordinary base 10, so this calculator first puts everything into seconds. |
| borrowing | In subtraction, taking 1 from the next place up when a place is too small to subtract from (also called regrouping). When you subtract times by hand, you borrow 60 instead of 10 (1 hour = 60 minutes, 1 minute = 60 seconds). |
| over midnight | When the date changes between the start and the end, as with an overnight bus or a night shift. If you calculate without dates, the end time is a smaller number than the start time, so the start is treated as the day before and one day, 86400 seconds, is added. (When you enter dates, the days between the dates are used instead.) |
| leap year | A year with a February 29 (about once every 4 years). When you count the days between two dates, a span that includes February 29 has one more day. This calculator counts it correctly, just as on the calendar. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back over these topics is the fastest way forward.
| Time of day and elapsed time (Grades 2–3) |
|
| AM, PM and the 24-hour clock (Grades 2–3) |
|
| Subtraction with borrowing (Grades 2–3) |
|
| Division with remainders (Grades 4–5) |
|
| Decimals (Grades 4–5) |
|
How to calculate it in Excel
| Hour (24-hour clock) | 17 |
| Minute | 30 |
| Second | 0 |
| Time in seconds | =B1*3600+B2*60+B3 |
| Start: hour (24-hour clock) | 8 |
| Start: minute | 30 |
| Start: second | 0 |
| End: hour (24-hour clock) | 17 |
| End: minute | 30 |
| End: second | 0 |
| Start in seconds | =B1*3600+B2*60+B3 |
| End in seconds | =B4*3600+B5*60+B6 |
| Elapsed time (s) | =IF(B8<B7,B8-B7+86400,B8-B7) |
| Elapsed: hours | =QUOTIENT(B9,3600) |
| Elapsed: minutes | =QUOTIENT(MOD(B9,3600),60) |
| Elapsed: seconds | =MOD(B9,60) |
| Start date and time | =DATE(2026,7,10)+TIME(22,0,0) |
| End date and time | =DATE(2026,7,12)+TIME(6,30,0) |
| Elapsed (difference in serial values = days) | =B2-B1 |
| Elapsed time shown as h:mm:ss | =TEXT(B2-B1,"[h]:mm:ss") |
| Total hours (decimal) | =(B2-B1)*24 |
In the second table, enter the start and end times in B1 to B6. B7 and B8 turn them into seconds (30600 and 63000), and B9 shows the elapsed time in seconds (32400). The IF function adds 86400 when the end is the smaller number, to handle spans over midnight. B10 to B12 split the seconds into hours, minutes and seconds with QUOTIENT (the whole-number part of a division) and MOD (the remainder). The answer is 9 hours 0 minutes 0 seconds.
The third table works across dates. When you build a date and time with the DATE and TIME functions, Excel stores it as a serial value (1 day = 1), so the subtraction in B3 alone gives the elapsed time as a decimal number of days (about 1.3542 days). The TEXT format "[h]:mm:ss" in B4 keeps counting hours past 24, so it shows "32:30:00", and B5 multiplies the serial value by 24 to get 32.5 total hours. Just replace the values in column B with your own.
How to calculate it in Google Sheets
| Hour (24-hour clock) | 17 |
| Minute | 30 |
| Second | 0 |
| Time in seconds | =B1*3600+B2*60+B3 |
| Start: hour (24-hour clock) | 8 |
| Start: minute | 30 |
| Start: second | 0 |
| End: hour (24-hour clock) | 17 |
| End: minute | 30 |
| End: second | 0 |
| Start in seconds | =B1*3600+B2*60+B3 |
| End in seconds | =B4*3600+B5*60+B6 |
| Elapsed time (s) | =IF(B8<B7,B8-B7+86400,B8-B7) |
| Elapsed: hours | =QUOTIENT(B9,3600) |
| Elapsed: minutes | =QUOTIENT(MOD(B9,3600),60) |
| Elapsed: seconds | =MOD(B9,60) |
| Start date and time | =DATE(2026,7,10)+TIME(22,0,0) |
| End date and time | =DATE(2026,7,12)+TIME(6,30,0) |
| Elapsed (difference in serial values = days) | =B2-B1 |
| Elapsed time shown as h:mm:ss | =TEXT(B2-B1,"[h]:mm:ss") |
| Total hours (decimal) | =(B2-B1)*24 |
How to calculate it in Python
from datetime import datetime
# Start and end date and time (use the same date if the span does not cross into another day)
start = datetime(2026, 7, 10, 22, 0, 0) # July 10, 2026, 22:00:00
end = datetime(2026, 7, 12, 6, 30, 0) # July 12, 2026, 6:30:00
duration = end - start # elapsed time (a timedelta)
total_seconds = int(duration.total_seconds()) # total seconds
hours, remainder = divmod(total_seconds, 3600) # hours and the seconds left over
minutes, seconds = divmod(remainder, 60) # split the rest into minutes and seconds
days, day_remainder = divmod(total_seconds, 86400) # for the display with days
print(f"Elapsed time: {hours} h {minutes} min {seconds} s")
print(f"With days: {days} d {day_remainder // 3600} h {day_remainder % 3600 // 60} min")
print(f"Total hours: {total_seconds / 3600} h")
print(f"Total minutes: {total_seconds / 60} min")
print(f"Total seconds: {total_seconds} s")
How to write it in LaTeX and other math languages (copy and paste)
T = 3600h + 60m + s
T = 3600h + 60m + s
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>T</mi><mo>=</mo>
<mn>3600</mn><mi>h</mi>
<mo>+</mo><mn>60</mn><mi>m</mi>
<mo>+</mo><mi>s</mi>
</mrow>
</math>
T = 3600h + 60m + s
totalSeconds = 3600*h + 60*m + s
T := 3600*h + 60*m + s;
T = 3600*h + 60*m + s;
T = 3600h + 60m + s
D = T₂ − T₁ (T₂ ≥ T₁), D = T₂ − T₁ + 86400 (T₂ < T₁)
D = T_2 - T_1 \quad (T_2 \ge T_1), \qquad D = T_2 - T_1 + 86400 \quad (T_2 < T_1)
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>D</mi><mo>=</mo>
<msub><mi>T</mi><mn>2</mn></msub><mo>−</mo>
<msub><mi>T</mi><mn>1</mn></msub>
<mo>,</mo><mspace width="0.7em"/>
<mi>D</mi><mo>=</mo>
<msub><mi>T</mi><mn>2</mn></msub><mo>−</mo>
<msub><mi>T</mi><mn>1</mn></msub>
<mo>+</mo><mn>86400</mn>
</mrow>
</math>
D = T_2 - T_1, D = T_2 - T_1 + 86400
durationSeconds = If[t2 >= t1, t2 - t1, t2 - t1 + 86400]
dur := `if`(t2 >= t1, t2 - t1, t2 - t1 + 86400); # D is reserved in Maple (the differential operator), so the name dur is used
if t2 >= t1, D = t2 - t1; else, D = t2 - t1 + 86400; end
D = T_2 - T_1 (T_2 ≥ T_1), D = T_2 - T_1 + 86400 (T_2 < T_1)
D = 60(h₂ − h₁) + (m₂ − m₁)
D = 60(h_2 - h_1) + (m_2 - m_1)
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>D</mi><mo>=</mo>
<mn>60</mn>
<mo>(</mo><msub><mi>h</mi><mn>2</mn></msub><mo>−</mo><msub><mi>h</mi><mn>1</mn></msub><mo>)</mo>
<mo>+</mo>
<mo>(</mo><msub><mi>m</mi><mn>2</mn></msub><mo>−</mo><msub><mi>m</mi><mn>1</mn></msub><mo>)</mo>
</mrow>
</math>
D = 60(h_2 - h_1) + (m_2 - m_1)
durationMinutes = 60*(h2 - h1) + (m2 - m1)
dur := 60*(h2 - h1) + (m2 - m1); # D is reserved in Maple (the differential operator), so the name dur is used
D = 60*(h2 - h1) + (m2 - m1);
D = 60(h_2 - h_1) + (m_2 - m_1)
D = 86400n + T₂ − T₁
D = 86400n + T_2 - T_1
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>D</mi><mo>=</mo>
<mn>86400</mn><mi>n</mi>
<mo>+</mo><msub><mi>T</mi><mn>2</mn></msub>
<mo>−</mo><msub><mi>T</mi><mn>1</mn></msub>
</mrow>
</math>
D = 86400n + T_2 - T_1
durationSeconds = 86400*n + t2 - t1
dur := 86400*n + T2 - T1; # D is reserved in Maple (the differential operator), so the name dur is used
D = 86400*n + T2 - T1;
D = 86400n + T_2 - T_1
How to have ChatGPT do the calculation
You are a time calculation assistant. Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing). The start is July 10, 2026 at 22:00:00 and the end is July 12, 2026 at 6:30:00 (both on the 24-hour clock). Find each of the following: 1. The elapsed time (in the form "X hours Y minutes Z seconds") 2. The elapsed time with days (in the form "X days Y hours Z minutes") 3. The total hours (as a decimal), total minutes and total seconds Find the elapsed time by subtracting Python datetime objects, and split it into hours, minutes and seconds with divmod. Show the formulas you used and the numbers from the execution result.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
