Boneyard Tools

Adding months to a date and the day-clamping rule

Why adding a month to the 31st does not always give another 31st, how day clamping works, and what to expect at month ends and leap days.

Why month arithmetic is not just adding 30 days

Calendar months are uneven, running from 28 to 31 days, so adding a month is a shift of the month field rather than a fixed number of days. If you simply added 30 or 31 days you would drift off the same day of the month over a year. Add to Date instead moves the month and year first and keeps the day number where it can. This matches how people read a calendar: one month after the 10th is the 10th, whatever the month lengths in between.

What day clamping does

A problem appears when the day does not exist in the target month, such as asking for the 31st of February. The clamping rule pins the day to the last valid day of that month, so January 31 plus one month becomes February 28, or February 29 in a leap year. Clamping only ever pulls the day down to fit; it never pushes into the following month. That keeps a month step from silently jumping two months ahead.

How weeks and days finish the job

After the month and year shift, the tool adds weeks and days as plain 24-hour offsets. Order matters here: one month plus five days from June 10 first lands on July 10, then steps to July 15. Doing days first could produce a different answer near a month boundary, so the fixed order keeps results predictable. Weeks are just seven-day multiples, added in the same pass as days.

Common places this rule bites

Monthly billing, subscription renewals and payment due dates all rely on this behavior when they start on the 29th, 30th or 31st. A loan dated the 31st will show shorter February gaps and full-length ones elsewhere. Knowing that the day clamps down, not up, helps you reconcile why two dates a month apart can be 28, 30 or 31 days in real terms while still counting as one calendar month.

Frequently asked questions

Does adding a month ever move me two months forward?

No. Clamping only shortens the day to fit the target month, so you always stay in the month you asked for. January 31 plus one month stays in February rather than spilling into March.

If I add then subtract a month, do I get the original date back?

Not always. Clamping can lose information: January 31 plus one month is February 28, and subtracting a month from February 28 gives January 28, not the 31st. Month arithmetic is not perfectly reversible near month ends.