2026-06-246 min read

How to Calculate Elapsed Time — Between Dates, Times and Deadlines

Calculate elapsed time between any two moments — hours worked, project duration, age in days, or time until a deadline. With formulas and examples.

Elapsed time is the amount of time that passes between two moments — a start point and an end point. Unlike a clock reading (which tells you what time it is right now), elapsed time answers 'how long did that take?' or 'how long until that happens?' You need it for timesheets, project tracking, SLA monitoring, age calculations, cooking timers, and deadline countdowns.

The concept sounds trivial until you hit edge cases: shifts that cross midnight, daylight saving transitions, leap years, or billing rules that require decimal hours. This guide walks through each scenario with formulas you can apply by hand or in code.

What elapsed time means

Elapsed time = end moment − start moment, expressed in a unit of your choice (seconds, minutes, hours, days). The result is always a non-negative duration when the end is after the start. Common use cases include calculating hours worked on a shift, measuring how long a deployment took, finding days between two calendar dates, or determining a person's age in days for medical or legal purposes.

Same-day calculation

When both times fall on the same calendar day, subtract the start time from the end time. Convert hours and minutes to a single unit first to avoid mistakes.

Example: shift from 09:15 to 17:45. Convert to minutes: start = 9×60 + 15 = 555 min; end = 17×60 + 45 = 1065 min. Elapsed = 1065 − 555 = 510 minutes = 8 hours 30 minutes.

Formula: elapsed minutes = (end_hour × 60 + end_minute) − (start_hour × 60 + start_minute). Divide by 60 for decimal hours: 510 / 60 = 8.5 hours.

Cross-midnight calculation

Naive subtraction breaks when a shift spans midnight. If someone clocks in at 22:00 and out at 06:00, subtracting 22 from 6 gives −16 hours — obviously wrong.

Fix: add 24 hours (1,440 minutes) to the end time when it is earlier than the start time. Elapsed = (6×60) − (22×60) + 1440 = 360 − 1320 + 1440 = 480 minutes = 8 hours. Alternatively, convert both times to Unix timestamps or full datetime objects and subtract — the datetime library handles the rollover automatically.

Multi-day duration

For spans across multiple calendar days, use full date-time arithmetic. Convert both moments to a common epoch (Unix timestamp, Julian day, or ISO datetime), subtract, then convert the difference to your target unit.

Example: project started 2026-03-01 09:00 and ended 2026-03-15 17:00. The elapsed time is 14 days, 8 hours = 344 hours = 20,640 minutes. Date-only calculations (ignoring time of day) count calendar days: March 15 minus March 1 = 14 days. Be explicit about whether you mean calendar days or 24-hour periods — they differ when start and end times are not midnight.

Elapsed time for billing: decimal hours

Many invoicing systems require decimal hours rather than '8 hours 30 minutes'. Convert minutes to a decimal fraction of an hour by dividing by 60.

MinutesDecimal hours
15 min0.25 hrs
20 min0.33 hrs
30 min0.5 hrs
45 min0.75 hrs
50 min0.83 hrs
60 min1.0 hrs
90 min1.5 hrs
120 min2.0 hrs

Round according to your contract — some clients require rounding to the nearest 6 minutes (0.1 hour), others bill in 15-minute increments. Always document your rounding policy on invoices to avoid disputes.

Elapsed time in code

JavaScript:
const start = new Date('2026-03-01T09:00:00');
const end = new Date('2026-03-15T17:00:00');
const elapsedMs = end.getTime() - start.getTime();
const elapsedHours = elapsedMs / (1000 * 60 * 60);

// Current elapsed time since a moment:
const since = Date.now() - start.getTime();
Python:
from datetime import datetime
delta = datetime(2026, 3, 15, 17, 0) - datetime(2026, 3, 1, 9, 0)
print(delta.total_seconds() / 3600)  # hours
SQL:
-- MySQL
SELECT TIMESTAMPDIFF(HOUR, '2026-03-01 09:00:00', '2026-03-15 17:00:00');

-- PostgreSQL
SELECT EXTRACT(EPOCH FROM (timestamp '2026-03-15 17:00' - timestamp '2026-03-01 09:00')) / 3600;

FAQ

What is elapsed time vs duration? They mean the same thing in everyday usage — the length of an interval between two points. 'Elapsed time' emphasises time that has passed since a start event; 'duration' is the more general term for any time span, including future ones ('the meeting duration is 45 minutes').

How do I calculate billable hours? Record start and end times for each task, convert each interval to decimal hours, sum them, and apply your rounding rule. Subtract unpaid breaks before converting. Many freelancers use 15-minute minimum billing increments.

How many days between two dates? For calendar days: (end_date − start_date) in days. In spreadsheets: =DATEDIF(start, end, 'D') in Excel or (end - start).days in Python. Remember that 'days between Jan 1 and Jan 3' can be 2 or 3 depending on whether you count inclusively.

How to calculate age in days? Subtract date of birth from today's date. In JavaScript: Math.floor((Date.now() - new Date('1990-06-15')) / (1000*60*60*24)). In Python: (date.today() - date(1990, 6, 15)).days. For legal age requirements, confirm whether the jurisdiction counts the birthday itself as day zero or day one.

Try it yourself

Time Duration Calculator

Calculate elapsed time between two dates or times — hours, days, and decimal billing hours.

Explore more tools in the Tools Directory.
Browse all articles →