Advertisement

Month calculator

Enter a starting date and an ending date to count complete calendar months. The page also shows the leftover days and the total day count.

Calculator

Whole months
2
Years, months and days
0 years, 2 months and 0 days
Total days
60

Advertisement

How this calculator works

A month counts as complete when the same day number has been reached in a later month, or when the last day of a shorter month has been reached. That second rule is what lets January 31 to February 28 count as one month. The remaining days are measured from the last complete month boundary, so the breakdown always adds back up to the calendar.

Formula

months = the largest m such that addMonths(start, m) is not after end, where addMonths clamps the day to the target month's length. years = floor(months / 12) and the leftover months = months mod 12. leftover days = O(end) - O(addMonths(start, months)). total days = O(end) - O(start).

Worked example

From 2024-01-31 to 2024-03-31 is two whole months, written as 0 years, 2 months and 0 days, across 60 total days. From 2026-11-01 to 2027-01-15 is two whole months and 14 days.

Advertisement

Frequently asked questions

Is January 31 to February 28 one month?

Yes, under the end-of-month rule used here. February has no 31st, so its last day stands in for the monthly anniversary. Some payroll systems instead require the same day number and would call this less than a month, so check the convention your contract uses.

How is this different from dividing the days by 30?

Dividing gives an approximation that ignores how long the actual months are. The counter moves month by month on the calendar, so February and July are treated differently, as they should be.

Can I count months in reverse?

Not here. Swap the dates to count forward. Reverse intervals are reported as an error so the sign does not silently change the meaning of the breakdown.

Why does the breakdown show years and months instead of only months?

Both are given. The whole-month figure is useful for comparisons, while the years and months form is the usual way to describe a length of service or a child's age.

Sources

Advertisement