How to add or subtract calendar months

Handle month-end dates without overflowing into the wrong month.

Months are not fixed durations

Adding one month is not the same as adding thirty days. The result should be computed by calendar fields under an explicit month-end rule.

The month-end problem

A target month may lack the original day number. Systems commonly clamp to the target month's final day, reject the input or preserve an end-of-month convention.

Document the rule

Billing, subscriptions and legal deadlines may use different policies. Tests should cover January 31, February, leap years and year boundaries.

Related month guides