Date & Time guide · 8 min read

How to calculate dates and durations correctly

Handle inclusive dates, leap years, business days, timestamps and time zones without introducing off-by-one errors.

Date calculations depend on rules that are easy to leave unstated. Does a range include both endpoints? Are weekends excluded? Which time zone gives a timestamp its meaning? The answer changes with the rule.

Key takeaways

  • Decide whether start and end dates are included.
  • Separate calendar dates from exact moments in time.
  • Confirm time zones and holiday calendars for real deadlines.

Define the boundaries

A duration from Monday to Tuesday can mean one elapsed day or two named calendar days. Write down whether each endpoint is included.

Let the calendar handle month length

Months are not a fixed number of days. Use calendar-aware addition for months and years instead of multiplying by an average.

Treat business days as a local rule

Weekdays are not the same as working days when public holidays, regional weekends or company closures apply.

Attach a time zone to moments

Unix timestamps represent exact moments, while a date such as 2026-08-16 does not. Convert timestamps in the intended zone before comparing displayed dates.

Check leap-day cases

Birthdays, annual renewals and year differences around February 29 may follow special legal or product rules. Test those boundaries explicitly.

Final check

A date answer is trustworthy only when the boundary, calendar and time-zone assumptions travel with it.

Try it now

Related Date & Time tools

All tools →

Try “make image smaller”, “jpg into pdf”, “pretty json” or “count my words”.