setDate() writes the calendar day-of-month (1–31) on a Date object in local time. This guide covers syntax, adding days, overflow normalization, return values, and comparisons with UTC setters.
01
Syntax
date.setDate(n)
02
Mutates
In place
03
1–31
Day input
04
Overflow
Auto month roll
05
+ days
getDate + n
06
Returns
Epoch ms
Fundamentals
Introduction
After reading a day with getDate(), you often need to change it—move a deadline, snap to the 1st of the month, or add seven days. setDate() is the local-time setter for that calendar day component.
Unlike getters, setters mutate the original Date. Clone first with new Date(date) when you need to preserve the old value.
Concept
Understanding the setDate() Method
Date.prototype.setDate(day) accepts an integer day-of-month. Values outside 1–31 are normalized—setting day 32 in January becomes February 1. That overflow behavior is what makes setDate(getDate() + n) the standard “add days” idiom.
The method returns the updated epoch milliseconds (same as getTime() after the change). For UTC day writes, use setUTCDate() instead.
💡
Beginner Tip
To add days: date.setDate(date.getDate() + 7). JavaScript adjusts month and year for you—no leap-year table required.
Foundation
📝 Syntax
JavaScript
dateObj.setDate(day)
Parameters
day — Integer day-of-month. Values below 1 or above the month length roll into adjacent months.
Return value
Updated epoch milliseconds after the change.
NaN if the Date was invalid before the call.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Set day to 15
date.setDate(15)
Add 7 days
date.setDate(date.getDate() + 7)
Read day after set
date.getDate()
Clone before mutate
const copy = new Date(date)
UTC day setter
date.setUTCDate(n)
Last day of month
new Date(y, m + 1, 0)
Compare
📋 setDate() vs Similar Methods
Pick the setter that matches the calendar field you need to change.
setDate()
local day
Day of month
getDate()
read
Getter pair
setUTCDate()
UTC day
UTC setter
setMonth()
month
Month index
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples use new Date(year, monthIndex, day) for predictable local dates.
📚 Getting Started
Change the day-of-month on an existing Date.
Example 1 — Set the Day to the 10th
Start on March 26, 2026 and move to the 10th of the same month.
JavaScript
const date = new Date(2026, 2, 26); // March 26, 2026
date.setDate(10);
console.log(date.getDate()); // 10
console.log(date.getMonth()); // 2 (March)
Use local setDate for user-facing calendars; use setUTCDate for UTC rules.
For countdowns, subtract getTime() values—do not decrement setDate each tick.
Combine with setMonth and setFullYear when changing multiple fields.
Compatibility
Browser & Runtime Support
Date.prototype.setDate() has been available since ES1. It works in every browser and Node.js.
✓ Baseline · ES1
Date.prototype.setDate()
Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.
99%Universal API
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Date.setDate()Excellent
Bottom line: Safe everywhere. Remember mutation, overflow normalization, and the setDate(getDate() + n) idiom.
Wrap Up
Conclusion
setDate() writes the local day-of-month on a JavaScript Date. Use it to set a specific day or add days via setDate(getDate() + n), and clone first when you must preserve the original instant.
Next, learn setFullYear() to change the year (and optionally month/day), or review getDate() for reading the day component.
Clone with new Date(d) before mutating shared dates
Pair with getDate() to verify the result
Use setUTCDate when rules follow UTC
Validate dates with Number.isNaN(date.getTime()) first
❌ Don’t
Assume day 31 exists in every month
Expect setters to return a new Date object
Mix local setters with UTC getters in one label
Manually build month-length tables for simple day adds
Use setDate alone for millisecond-precision countdowns
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.setDate()
Your foundation for local day writes in JavaScript.
5
Core concepts
📝01
Syntax
date.setDate(n)
API
🔄02
Mutates
In place.
Behavior
➕03
+ days
getDate + n.
Pattern
📈04
Overflow
Auto roll.
Normalize
🔢05
Returns
Epoch ms.
Return
❓ Frequently Asked Questions
It sets the day-of-month (1–31) of a Date object in local time. The Date is mutated in place and the method returns the updated epoch milliseconds.
getDate() reads the current local day-of-month. setDate(day) writes a new day-of-month. They are the classic read/write pair for calendar days.
JavaScript normalizes overflow into the next month. setDate(32) on January rolls to February 1 (or Feb 2 in leap years depending on the starting date).
Use date.setDate(date.getDate() + 7). Overflow is handled automatically—no manual month-length table needed.
setDate() changes the local calendar day. setUTCDate() changes the UTC calendar day. Use the one that matches your timezone rules.
Yes. It returns the updated timestamp in milliseconds since the Unix epoch—the same value as calling getTime() after the change.
Did you know?
date.setDate(date.getDate() + 7) is the standard way to add a week in JavaScript—overflow rolls into the next month automatically, so Jan 28 + 7 becomes Feb 4 without a manual calendar table.