setMonth() writes the calendar month (0–11) on a Date in local time, with an optional day-of-month. This guide covers zero-indexed months, end-of-month overflow, and relative month shifts.
01
Syntax
setMonth(m)
02
0–11
Jan = 0
03
Day arg
Optional
04
Overflow
Jan 31 trap
05
+ months
getMonth + n
06
Returns
Epoch ms
Fundamentals
Introduction
Billing cycles, subscription renewals, and “three months from today” rules need to change the month on a Date. After reading the month with getMonth(), setMonth() writes it back in local time.
Months are zero-indexed: January is 0, December is 11. Like other setters, setMonth() mutates the Date and returns epoch milliseconds—not the Date for chaining.
Concept
Understanding the setMonth() Method
Date.prototype.setMonth(monthIndex [, day]) accepts a month index and an optional day (1–31). When you omit day, the current day-of-month is kept—it does not reset to the 1st.
End-of-month dates can surprise you: Jan 31 plus February becomes March 3 in a non-leap year because February has only 28 days. For UTC month writes, use setUTCMonth().
💡
Beginner Tip
April = 3, not 4. To jump to June 15: date.setMonth(5, 15). To add three months: date.setMonth(date.getMonth() + 3).
setMonth() writes the local calendar month (0–11) and optionally the day on a JavaScript Date. Use it for renewals and season shifts; watch end-of-month overflow and clone when preserving the original date.
Next, learn setSeconds() to change the second component, or review getMonth() for reading the month index.
Use named constants (const APRIL = 3) for readability
Clone before mutating shared Date instances
Test Jan 31 and leap-year February transitions
Use setMonth(m, 1) when you need the first of a month
❌ Don’t
Pass human month numbers 1–12 without subtracting 1
Assume omitted day resets to the 1st
Chain setters on the numeric return value
Ignore overflow when moving from 31-day months
Mix local setters with UTC getters in one label
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.setMonth()
Your foundation for local month writes in JavaScript.
5
Core concepts
📝01
Syntax
setMonth(m)
API
🔢02
0–11
Jan = 0.
Index
📅03
Day kept
If omitted.
Default
⚠04
Jan 31
Overflow trap.
Pitfall
➕05
+ months
getMonth + n.
Pattern
❓ Frequently Asked Questions
It sets the month index (0–11) of a Date object in local time. An optional day argument can also set the day-of-month. The Date mutates in place and returns updated epoch milliseconds.
JavaScript Date months are zero-indexed like getMonth(): 0 = January through 11 = December. April is index 3, not 4.
No. If you pass only the month index, the current day-of-month stays the same unless overflow normalization changes it (e.g. Jan 31 → February rolls into March).
February has fewer days than 31. JavaScript normalizes overflow—Jan 31, 2026 becomes March 3, 2026 (Feb 28 + 3 days).
No. It returns a number (epoch milliseconds). Call each setter on the same Date variable—do not chain on the return value.
setMonth() changes the local calendar month. setUTCMonth() changes the UTC calendar month. Use the one that matches your timezone rules.
Did you know?
Human month numbers (1–12) are not what setMonth() expects—subtract 1. And when you omit the day argument, the day stays put; only overflow (like Jan 31 → Feb) changes it.