Show a date as time ago

Express the elapsed difference between two instants as an English label such as “2 days ago.”

freeworks offlinenothing uploaded
ToolRelative Time
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

The target timestamp is subtracted from the current or supplied reference timestamp, then the absolute difference is floored through seconds, minutes, hours, days, weeks, approximate months, and approximate years. The threshold selects the displayed unit and the sign chooses ago or from now.

  • Differences under five seconds read just now.
  • Months use 30.44 days and years use 365.25 days, so the labels measure duration rather than calendar boundaries.

Worked example

Two days earlier
Compare an instant with a fixed reference time
Input
											Input: 2026-01-13T12:00:00Z
Reference time: 2026-01-15T12:00:00Z
										
Output
												2 days ago
(2026-01-13T12:00:00.000Z)
											

When to use this

Activity feeds label saved timestamps, release dashboards show time before an ISO deployment instant, and log viewers turn Unix timestamps into age labels.

Edge cases

  • A date 30 days earlier can remain four weeks because the month threshold uses 30.44 days.
  • A daylight-saving boundary is measured by elapsed milliseconds, not by the number of local clock dates crossed.
  • A numeric value below 4,102,444,800 is interpreted as Unix seconds, while larger numeric input is treated as milliseconds.

References