JavaScript Date setDate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.setDate() changes the day of the month of a Date according to local time. It mutates the object in place and returns the new epoch milliseconds.

Remember
date.setDate(dayOfMonth)

dayOfMonth = 1 … 31 for a normal day
dayOfMonth = 0      → last day of previous month
dayOfMonth = 32+    → overflows into next month

→ mutates date
→ returns new epoch ms (or NaN if invalid)

Syntax

Call date.setDate. Start with this line.

JavaScript
date.setDate(dateValue)
CallWhat it does
date.setDate(dateValue)Primary signature.
date.setDate(...)Call with the arguments your case needs.

Built into JavaScript. Call setDate(...) on a Date instance — no import required.

Library declarations
JavaScript
date.setDate(dateValue)

Parameters

ParameterDescription
dateValueRequired. Day of month (integer; out-of-range OK)

Return Value

Return ValueDescription
*New epoch ms (same as getTime())

JavaScript Examples

Example 1 — Set the Day of the Month

Change the local day, then read it back with getDate().

JavaScript
const event = new Date("August 19, 1975 23:15:30");
event.setDate(24);

console.log(event.getDate()); // 24
Try It Yourself

How It Works

  1. Start with a date. August 19, 1975 is the baseline.
  2. Write the day. setDate(24) stores day 24.
  3. Read it back. getDate() returns 24.
  4. Mutates. The same event object is updated in place.

Example 2 — Day Overflow into Next Month

Values past the month length roll forward automatically.

JavaScript
const event = new Date("August 19, 1975 23:15:30");
event.setDate(32); // August has 31 days

console.log(event.getDate());  // 1
console.log(event.getMonth()); // 8 (September; months are 0-indexed)
Try It Yourself

How It Works

  1. Out of range. Day 32 is past August’s 31 days.
  2. Normalize. The engine rolls into September 1.
  3. Day field. getDate() is 1.
  4. Month field. getMonth() is 8 (September).

Example 3 — Add Days with getDate() + n

The usual pattern for “one week later” without a manual calendar table.

JavaScript
const d = new Date(2026, 0, 10); // Jan 10, 2026
d.setDate(d.getDate() + 7);

console.log(d.getDate());  // 17
console.log(d.getMonth()); // 0 (still January)
Try It Yourself

How It Works

  1. Read current day. getDate() is 10.
  2. Add offset. 10 + 7 → pass 17 to setDate.
  3. Same month. January still has room, so month stays 0.
  4. Near month end. The same pattern still works — overflow rolls months for you.

Browser & Runtime Support

Date.prototype.setDate() is part of the language from early ECMAScript and is Baseline Widely available (MDN).

✓ Baseline · Widely available

Date.prototype.setDate()

Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.

99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.setDate() Excellent

Bottom line: Safe everywhere. Focus on overflow rules and local vs UTC choice rather than feature detection.

Frequently Asked Questions

It sets the day of the month (1–31) on a Date in local time. The Date is changed in place, and the method returns the new epoch milliseconds.
getDate() reads the local day of the month. setDate(day) writes a new day. They are the read/write pair for calendar days.
JavaScript normalizes overflow into the next month. On a 31-day month, setDate(32) becomes the 1st of the following month (MDN).
Use date.setDate(date.getDate() + 7). Overflow across month boundaries is handled automatically.
It sets the date to the last day of the previous month. Useful for “end of last month” calculations.
setDate() changes the local calendar day. setUTCDate() changes the UTC calendar day. Prefer UTC setters for timezone-agnostic logic.

Next: setFullYear()

Learn how to set the full year on a Date in local time.

setFullYear() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful