EpochMasters Logo
Epoch Duration & Elapsed Time

Timestamp Difference Calculator

Compare two Unix timestamps or dates to determine the exact elapsed duration. View differences broken down into days, hours, minutes, and seconds.

Epoch Offset Calculator

Add or subtract time units from an epoch

Timestamp Difference

Compute precise time difference between two epochs

Calculating Elapsed Time Between Two Timestamps

Because a Unix timestamp represents a continuous numeric timeline in seconds, determining the elapsed duration between any two events requires only subtraction. No timezone conversions are required, because both points in time are globally normalized to UTC:

Total Seconds Elapsed = |Timestamp B - Timestamp A|

Once total seconds are calculated, software decomposes the value into human-friendly units using integer division (floor) and modulus operations.

Duration Calculation in Code (JavaScript, Python, SQL)

JavaScript / TypeScriptFormatted Duration Function
function formatDuration(epochA, epochB) {
  const delta = Math.abs(epochB - epochA);
  const days = Math.floor(delta / 86400);
  const hours = Math.floor((delta % 86400) / 3600);
  const minutes = Math.floor((delta % 3600) / 60);
  const seconds = delta % 60;
  return `${days}d ${hours}h ${minutes}m ${seconds}s`;
}
console.log(formatDuration(1730100000, 1730195400));
Python 3datetime difference & timedelta
from datetime import datetime, timezone

dt1 = datetime.fromtimestamp(1730100000, tz=timezone.utc)
dt2 = datetime.fromtimestamp(1730195400, tz=timezone.utc)
duration = abs(dt2 - dt1)

print("Days:", duration.days)
print("Total Seconds:", int(duration.total_seconds()))
SQL (PostgreSQL & MySQL)Calculating Request Latency
-- When timestamps are integers (seconds):
SELECT (completed_epoch - started_epoch) AS duration_seconds FROM audit_logs;

-- When timestamps are PostgreSQL TIMESTAMPTZ:
SELECT AGE(completed_at, started_at) AS elapsed_time FROM job_queue;

Typical Use Cases for Comparing Timestamps

API & SLA Tracking

Measuring API response times, job execution latency, and verifying if batch processes met Service Level Agreements (SLAs).

User Session Duration

Determining active session lengths, idle timeouts, and token refresh validity windows across distributed authentication systems.

Explore Related Utilities