Skip to content
ToolkitHub

Date Difference Calculator

Calculate date differences

Guide

Counting the days, months and years between dates

By Logappradeep · ServiceNow developer

"How long until the contract ends?" "How many days was the project late?" "How old is this account?" Questions like these sound trivial until you try to answer them by hand. Months have 28 to 31 days, leap years add a day, and people disagree about whether to count the first and last day. A date difference calculator applies one consistent set of rules.

How the calculation works

Pick a start date and an end date, and the tool shows three numbers:

  • Days: the number of complete days between the two dates.
  • Months: the number of complete calendar months.
  • Years: the number of complete calendar years.

The result is always positive, so the order of the dates does not matter. Months and years count only full periods. For example, from January 15, 2026 to March 14, 2026 is 58 days (16 left in January, 28 in February, 14 in March) but only 1 month, because the second full month would not be complete until March 15. Each number is a separate measure of the same span, not parts to add together.

Inclusive versus exclusive counting

The day count measures the gap between dates, so the end date is not counted. From Monday to Friday of the same week is 4 days. If you are counting days of attendance, hotel nights versus hotel days, or a leave request where both the first and last day count, add 1 to the result. Getting this wrong is the most common source of off-by-one errors in date math.

Leap years

A year is a leap year if it is divisible by 4, except century years, which must also be divisible by 400. So 2024 and 2028 are leap years, 1900 was not, and 2000 was. A full year spanning February 29 has 366 days, which is why "one year" and "365 days" are not always the same.

Common uses

  • Checking notice periods, warranty windows and subscription terms.
  • Calculating project durations or the length of a sprint or release cycle.
  • Working out someone's age in full years on a given date.
  • Verifying date logic in code by comparing against a known result.

Pitfalls in code

Dividing a millisecond difference by 86,400,000 gives wrong answers around daylight saving time changes, when a local day is 23 or 25 hours long. Use a date library function that counts calendar days instead. Adding one month to January 31 has no single correct answer, since February has no 31st, so libraries clamp to the end of the month. Be explicit about which behavior your business rules expect. And remember that this tool counts calendar days, not business days; weekends and public holidays are included.

Calculations use the date-fns library in your browser, and your last two dates are remembered in local storage.

Frequently asked questions

Does the result include the end date?

No. It counts the days between the dates, so Monday to Friday is 4 days. Add 1 if you need to include both dates.

Why does the month count look low?

Months and years count only complete periods. January 15 to March 14 is 1 full month, even though it is 58 days.

Does it count business days?

No. It counts calendar days, including weekends and holidays.

Does it handle leap years?

Yes. February 29 is counted in leap years, so spans that include it have one more day.