Skip to main content
DATE & DURATION

Timestamp Difference

Enter two Unix timestamps to get the time between them in milliseconds, seconds, minutes, hours and days.

Calculate the difference between two timestamps

Enter two Unix timestamps and the calculator returns the gap in milliseconds, seconds, minutes, hours and days, plus a human-readable duration such as 2 days 4 hours 12 minutes 30 seconds. The result is always a positive amount, with a sentence telling you which timestamp comes first.

Common uses

Measure how long a job ran from two log lines, check how long a session or token lived, work out the time left until an expiry, or find the age of a record. Each field has its own Unit setting, so you can compare a value in seconds with a value in milliseconds.

Want the background? Read our comprehensive guide: What Is Unix Time?.

How to use this tool

  1. Enter Timestamp A and Timestamp B, or select Use current time on either field.
  2. Set the unit of each timestamp, or leave both on Auto.
  3. Select Calculate difference.
  4. Read the totals and the human-readable duration. Swap A and B to reverse the direction.

Examples

Timestamp B is later than timestamp A in this example.

Two days, four hours, twelve minutes and thirty seconds

A = 1790000000, B = 1790187950 (seconds)

Human-readable
2 days 4 hours 12 minutes 30 seconds
Seconds
187950
Hours
52.208333

Timestamps in different units

A = 1790000000 (seconds), B = 1790000000500 (milliseconds)

Human-readable
500 milliseconds

Each timestamp has its own unit setting, and Auto detects each one separately.

A full day apart

A = 1790000000, B = 1790086400 (seconds)

Human-readable
1 day
Hours
24

Frequently Asked Questions

How do I calculate the difference between two timestamps in code?
Subtract the earlier timestamp from the later one. If both are in seconds the result is in seconds, and you divide by 60, 3,600 or 86,400 for minutes, hours or days.
Are months and years included?
No. Months and years have different lengths, so the tool reports exact days, hours, minutes and seconds instead of approximations.
Can I mix seconds and milliseconds?
Yes. Each timestamp has its own unit setting, and Auto detects the unit of each one separately.
Does daylight saving time change the result?
No. Unix timestamps are in UTC, so the difference is the exact elapsed time. Only differences between local calendar times can shift by an hour around a clock change.