JavaScript Date setDate() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Local day setter

What You’ll Learn

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

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.

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.

📝 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.

⚡ Quick Reference

GoalCode
Set day to 15date.setDate(15)
Add 7 daysdate.setDate(date.getDate() + 7)
Read day after setdate.getDate()
Clone before mutateconst copy = new Date(date)
UTC day setterdate.setUTCDate(n)
Last day of monthnew Date(y, m + 1, 0)

📋 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

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)
Try It Yourself

How It Works

Only the day changes—month and year stay the same when the new day fits in the current month.

📈 Practical Patterns

Adding days, return values, overflow, and month-end helpers.

Example 2 — Add Seven Days with setDate(getDate() + 7)

The classic idiom for relative deadlines and reminders.

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

console.log(date.getMonth()); // 1 (February)
console.log(date.getDate());  // 4
Try It Yourself

How It Works

Jan 28 + 7 days overflows January into February 4. The engine handles month length automatically.

Example 3 — Use the Return Value (Epoch Milliseconds)

setDate returns the updated timestamp—useful for chaining or storage.

JavaScript
const date = new Date(2026, 2, 15);
const ms = date.setDate(20);

console.log("Returned ms:", ms);
console.log("getTime() matches:", ms === date.getTime()); // true
Try It Yourself

How It Works

All Date setters return epoch ms on success. Compare with getTime() after mutating to confirm.

Example 4 — Month Overflow Normalization

Passing day 31 to February rolls into March.

JavaScript
const date = new Date(2026, 1, 15); // Feb 15, 2026
date.setDate(31);

console.log(date.getMonth()); // 2 (March)
console.log(date.getDate());  // 3
Try It Yourself

How It Works

February 2026 has 28 days. Setting day 31 advances into March 3. This is intentional engine behavior, not an error.

Example 5 — Jump to the Last Day of a Month

Use day 0 of the next month to land on the previous month’s last day.

JavaScript
const date = new Date(2026, 2, 10); // March 10, 2026
date.setMonth(3, 0); // day 0 of April = last day of March

console.log(date.getDate()); // 31
Try It Yourself

How It Works

setMonth(monthIndex, day) accepts a day argument. Day 0 means “last day of the previous month.” Pair with setMonth() for billing-period end dates.

🚀 Common Use Cases

  • Relative deadlines — add N days with setDate(getDate() + n).
  • Billing cycles — snap to month-end or the 1st.
  • Calendar UI — update the selected day when user picks a date.
  • Reminder apps — shift events by whole days in local time.
  • Form defaults — pre-fill “due in 14 days” on a Date field.
  • Clone + mutate — copy a Date before calling setDate to keep originals.

🧠 How setDate() Updates the Calendar Day

1

Read current parts

Engine loads local year, month, and day from the Date.

Local
2

Apply new day

The day argument replaces the day-of-month component.

setDate
3

Normalize overflow

Out-of-range days roll into adjacent months/years.

Normalize
4

Mutate & return ms

The Date updates in place; epoch milliseconds are returned.

📝 Notes

  • setDate() mutates the original Date—clone if you need the old value.
  • Overflow is normalized automatically—ideal for adding days, surprising if you expected clamping.
  • Returns epoch milliseconds; invalid dates yield NaN.
  • 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.

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 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. Remember mutation, overflow normalization, and the setDate(getDate() + n) idiom.

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.

💡 Best Practices

✅ Do

  • Use setDate(getDate() + n) to add days
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.setDate()

Your foundation for local day writes in JavaScript.

5
Core concepts
🔄 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.

Continue to setFullYear()

Learn how to change the year (and optionally month and day) on a Date object.

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.

6 people found this page helpful