Timestamps and scheduling guides

Date differences: elapsed hours vs calendar days

Calculate elapsed time from instants and keep billing, business-day and calendar rules separate.

Nav Tools ·

Subtract instants for duration

Two timestamps can be subtracted to obtain elapsed milliseconds. Divide by a chosen unit to obtain a duration in hours or seconds.

This arithmetic does not automatically count inclusive calendar dates or business days. Name the result according to what was actually measured.

2024-01-01T00:00:00Z → 2024-01-02T00:00:00Z
Elapsed: 86,400 seconds = 24 hours

A local day may not be 24 hours

Across a daylight-saving transition, consecutive local midnights can be 23 or 25 hours apart. Calendar-day counting can still report one day.

For New York’s spring 2024 change, midnight-to-midnight across March 10 spans 23 hours. Preserve the zone when the rule is calendar based.

2024-03-10T00:00:00-05:00
2024-03-11T00:00:00-04:00
Elapsed: 23 hours

Months and business days need rules

A month is not a constant number of seconds. Adding a month to a month-end date requires a rule for missing destination days.

Business-day calculations need a locale, weekend definition and holiday calendar. Nav Tools’ basic date difference does not supply every jurisdiction’s holiday policy.

Agree on endpoints and rounding

Decide whether a range includes its start and end and whether fractional durations are rounded, truncated or preserved. Billing depends on those choices.

Test equal instants, reversed endpoints and a subday difference. Keep the raw elapsed value before applying domain-specific rounding.

References

← Timestamps and scheduling guides