日期差计算器

精确计算两个日期之间的间隔,单位包括天、周、月和年,同时显示星期和总小时数。

How the calculation works

There is more than one sensible way to express a duration, and they give different answers:

  • Total days — every 24-hour period between the two dates, including leap days
  • Calendar months and years — follows the calendar, so January 31 to February 28 is one month
  • Weeks — total days divided by seven

The tool shows all of them so you can pick the one that matches your question.

The leap year rule

A year is a leap year if it is divisible by 4, except centuries, which must be divisible by 400. So 2000 was a leap year, 1900 and 2100 are not. The rule has applied since 1582 and handles the Gregorian calendar exactly.

Common uses

  • Age calculation — the legal age in most countries is the anniversary, not the calendar year difference
  • Contract terms — "30 days from the effective date" usually excludes the start date
  • Project planning — counting working days requires excluding weekends and holidays
  • Countdown to a deadline — the tool shows the direction of the difference

A note on inclusive vs exclusive counting

If you count from January 1 to January 2, is that 1 day or 2? The tool uses the difference in timestamps, which gives 1. For inclusive counting — where both endpoints count — add one. Most date libraries use exclusive counting by default, which is the more common source of off-by-one errors.

常见问题

How is the duration calculated?

The difference between the two timestamps, which counts every 24-hour period including leap days. It also shows a calendar-based year and month breakdown.

Why do the day count and the month count disagree?

They measure different things. Total days are exact 24-hour periods; months follow the calendar, so January 31 to February 28 is one month.

Is the end date included?

No. The tool uses the difference between the timestamps, which is the exclusive count most date libraries use. Add one for inclusive counting.

How are leap years handled?

A year is a leap year if divisible by 4, except centuries, which must be divisible by 400. So 2000 was a leap year, and 1900 and 2100 are not.

Can I leave the second date empty?

Yes, it defaults to the current date and time.