Staaarter

Find Time Difference

Calculates the elapsed duration between two clock times entered one per line, formatted as hours, minutes, and seconds. If the second time is earlier than the first, it is treated as occurring the following day. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
durationcalculator

Overview

Introduction

Working out how much time passed between two clock readings, like a shift start and end time, is a common task that's easy to get wrong by hand, especially across midnight.

This tool calculates the exact duration and correctly wraps to the next day when the second time is earlier than the first.

What Is Find Time Difference?

A calculator that takes exactly two clock times, one per line, and returns the elapsed duration between them as hours, minutes, and seconds.

It assumes both times fall within a single continuous span, wrapping to the next calendar day automatically if the second time appears earlier.

How Find Time Difference Works

Each time is parsed into its seconds-since-midnight value, then the first is subtracted from the second.

If that difference is negative, a full day's worth of seconds (86400) is added, representing the second time occurring the following day, before the result is broken into hours, minutes, and seconds.

When To Use Find Time Difference

Use it to calculate a work shift's length, an event's duration, or the gap between two logged clock times.

For the difference between two calendar dates rather than two times of day, use Find Date Difference instead.

Features

Advantages

  • Automatically wraps to the next day when the second time is earlier, no manual adjustment needed for overnight spans.
  • Accepts HH:MM or HH:MM:SS for either time.
  • Returns a clear, human-readable "Xh Ym Zs" result.

Limitations

  • Assumes a single-day wraparound at most, it cannot represent spans longer than 24 hours since only clock times, not dates, are provided.
  • Does not account for timezone differences between the two times.

Examples

Calculating a same-day span

Input

09:15
17:45

Output

8h 30m 0s

From 09:15 to 17:45 is 8 hours and 30 minutes.

Calculating an overnight span

Input

22:00
02:00

Output

4h 0m 0s

02:00 is earlier than 22:00, so it's treated as the next day, giving a 4-hour overnight span.

Best Practices & Notes

Best Practices

  • Enter the start time first and the end time second, the tool assumes that order when deciding whether to wrap to the next day.
  • Include seconds in both times if you need precision finer than a minute.

Developer Notes

Both lines are parsed with `/^([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/` into seconds-of-day integers, `diff = second - first` is computed, and if negative, 86400 is added before breaking the result into hours, minutes, and seconds via floor division and modulo.

Find Time Difference Use Cases

  • Calculating the length of a work shift from clock-in and clock-out times
  • Finding the duration of an overnight event that spans midnight
  • Quick manual verification of an elapsed-time calculation in code

Common Mistakes

  • Entering the times in the wrong order, which changes whether the calculation wraps to the next day.
  • Expecting spans longer than 24 hours to work, since only clock times are provided, the result always falls between 0 and 24 hours.

Tips

  • For spans longer than a day, calculate the whole-day count separately with Find Date Difference and add the leftover hours from this tool.
  • Use Convert Time to Seconds if you need the raw seconds count of one of the input times.

References

Frequently Asked Questions