How this calculator works
Years and months are applied on the calendar first, keeping the same day number where that day exists in the target month. A start date of January 31 plus one month therefore lands on February 28 or 29, not on March 3. Whole weeks and days are then applied as exact day counts on the proleptic Gregorian calendar. The net change counts every day crossed, including weekends and leap days.
Formula
Let S be the start date. First M = addMonths(S, sign x (12 x years + months)), where the day is clamped to the length of the target month. Then E = fromOrdinal(O(M) + sign x (7 x weeks + days)). The net change is O(E) - O(S), where O is the day number from 0001-01-01.
Worked example
2026-11-01 plus one month is 2026-12-01, a Tuesday, for a net change of 30 days. Adding one month to 2024-01-31 gives 2024-02-29, the last day of February in a leap year. Subtracting one year and one day from 2025-03-01 gives 2024-02-29.
Advertisement
Frequently asked questions
Why does adding a month on the 31st sometimes give the 28th?
Because the target month has no 31st. The page clamps to the last day of that month, which is the usual calendar convention. This avoids skipping into the next month and is the same rule used by date libraries for a month step.
In what order are years, months, weeks and days applied?
Years and months are combined into one calendar step, then weeks and days are applied as exact days. The order matters: one month plus one day from January 31 differs from one month from January 31 and then one day.
Does this handle daylight saving time?
No. It is pure date arithmetic with no clock time, so there is no hour to shift. A civil calendar day is always one day apart, even when a bank of clocks changes in between.
How is this different from the date calculator?
The date calculator adds only a number of days. This page also adds years and months, which vary in length and need the end-of-month rule.