
The Right Way to Add Months to a Date in JavaScript (It's Not What You Think)
"What date is 1 month from today?" For March 24, the intuitive answer is April 24. Simple. But what about January 31? Is one month later February 28? February 31? March 3? Date arithmetic involving months is genuinely ambiguous, and the way JavaScript handles it will surprise you. What JavaScript Actually Does const d = new Date ( ' 2026-01-31 ' ); d . setMonth ( d . getMonth () + 1 ); // "Add 1 month" console . log ( d . toISOString ()); // "2026-03-03T00:00:00.000Z" You asked for February, you got March 3. What happened? JavaScript's setMonth works by setting the month field and letting overflow cascade. February has 28 days in 2026, so "February 31" overflows to March 3. This behavior is defined in the spec — it's not a bug. But it's almost certainly not what your users expect. Three Different Conventions There's no universally correct answer to "Jan 31 + 1 month." Different systems use different conventions: Convention Result Used by Overflow (JS default) March 3 Raw JS Date math C
Continue reading on Dev.to Beginners
Opens in a new tab


