Add days to a date in JavaScript (UTC, local, DST caveats)

How to javascript add days to date and js date add days: getUTCDate/setUTCDate for UTC calendar days, getDate/setDate for local wall calendar, immutable copy pattern, getTime + 86400000 ms vs DST, negative days, and Intl for display. Examples use fixed Date.UTC instants where noted.

Published

Updated

Read time 4 min read

Reviewed byDeepak Prasad

Add days to a date in JavaScript (UTC, local, DST caveats)

Javascript add days to date and js date add days usually mean calendar arithmetic: add n whole days while letting Date roll over months and years. Use getDate / setDate for local wall time or getUTCDate / setUTCDate for UTC. Adding n * 86400000 ms to getTime() is a fixed 24-hour step (not always the same as a local calendar day across DST). After you compute the instant, format with Intl.DateTimeFormat—see JavaScript date formatting with Intl.DateTimeFormat.

Tested on: Node.js v20.18.2. Examples use fixed Date.UTC instants so totals stay stable across machines; each snippet is followed by a short note describing the printed lines.


Quick reference

Calendar-day math mutates date fields (setUTCDate / setDate); millisecond math moves a fixed duration on the timeline—those differ around DST.

Need Pattern
UTC calendar ± days setUTCDate(getUTCDate() + n) on a Date
Local calendar ± days setDate(getDate() + n)
Fixed 24-hour steps new Date(d.getTime() + n * 86400000)
Don’t mutate shared values new Date(d) first

1. setUTCDate / getUTCDate — javascript date add days in UTC

UTC setters keep servers and APIs aligned regardless of the reader’s local zone—pair getUTCDate with setUTCDate so month rollover stays in UTC.

javascript
const d = new Date(Date.UTC(2026, 5, 9, 12, 0, 0)); // 2026-06-09 12:00 UTC
console.log(d.toISOString());
d.setUTCDate(d.getUTCDate() + 5);
console.log(d.toISOString());
Output

You should see 2 lines: 2026-06-09T12:00:00.000Z, then 2026-06-14T12:00:00.000Z.

Month indexing is 0-based (5 = June).


2. Immutable helper (add days to date javascript without mutating the input)

Return a fresh Date when callers might still hold the original reference—mutating a shared instance is a common source of off-by-timezone bugs.

javascript
function addDaysUTC(date, days) {
  const x = new Date(date);
  x.setUTCDate(x.getUTCDate() + days);
  return x;
}

const start = new Date(Date.UTC(2026, 5, 9, 12, 0, 0));
console.log(addDaysUTC(start, 5).toISOString());
console.log(start.toISOString());
Output

You should see 2 lines: 2026-06-14T12:00:00.000Z, then 2026-06-09T12:00:00.000Z.


3. getTime() + milliseconds — js add days to date by timestamp

Adding n * 86400000 shifts the instant by n solar days only when you stay in a context where each day is 24h (UTC math); compare with §5 for local DST edges.

javascript
const days = 5;
const t = new Date(Date.UTC(2026, 5, 9, 12, 0, 0)).getTime() + days * 86400000;
console.log(t);
console.log(new Date(t).toISOString());
Output

You should see 2 lines: 1781438400000, then 2026-06-14T12:00:00.000Z.

One day = 24 * 60 * 60 * 1000 = 86400000 milliseconds (not minutes).


4. Subtract days (javascript date add day with a negative n)

setUTCDate accepts out-of-range day values; negative offsets walk backward through month boundaries the same way positive offsets roll forward.

javascript
const d = new Date(Date.UTC(2026, 5, 9, 12, 0, 0));
d.setUTCDate(d.getUTCDate() - 10);
console.log(d.toISOString());
Output

You should see one line like: 2026-05-30T12:00:00.000Z.


5. Local calendar days: setDate / getDate

When the requirement is the viewer’s local wall calendar (not a fixed UTC instant), use getDate / setDate and document that choice—logs will vary by machine zone. Rollover rules mirror UTC field math, but elapsed wall time can differ from n * 86400000 ms across DST; see MDN setDate. Prefer setUTCDate for timezone-stable server math.


6. Libraries

Heavy calendar UIs usually adopt date-fns, Day.js, or (eventually) Temporal so policy lives in one place—still know the Date primitives above for code review and debugging.


Summary

Pick UTC field setters for APIs and servers, local field setters for UX copy tied to the user’s calendar, and timestamp math when you truly mean fixed 24-hour steps.

  • Prefer setUTCDate / getUTCDate for UTC calendar days; use setDate / getDate for local wall-calendar days.
  • Millisecond offsets are fixed 24-hour steps; they can diverge from “calendar day” near DST in local zones.
  • Copy with new Date(d) before mutating when callers must keep the original reference.
  • Format results with Intl or your UI layer after the instant is correct.

References

MDN references for calendar mutation and timestamps used in add days to date js flows.


Frequently Asked Questions

1. How do I javascript add days to date without changing the original?

Copy first: const out = new Date(d); then out.setUTCDate(out.getUTCDate() + n) or the local equivalent with setDate. Mutating a shared Date causes subtle bugs.

2. Should I use setDate or setUTCDate for javascript date add days?

Use getUTCDate/setUTCDate when you mean calendar days in UTC (servers, APIs). Use getDate/setDate for the user's local calendar—including how midnight and DST are interpreted.

3. Is adding 5 * 86400000 milliseconds the same as adding five calendar days?

Usually yes in UTC. In local time, five calendar days via setDate can differ from five exact 24-hour steps across a daylight-saving transition; MDN discusses this under setDate.

4. Can I add a negative number of days?

Yes. getUTCDate() + days and setUTCDate accept values that roll backward into the previous month the same way forward values roll forward.

5. Why avoid Date.prototype.addDays?

Extending built-in prototypes affects all code in the realm, collides with other libraries, and is discouraged in modern style guides. Use a plain function instead.

6. How do I format the result for users?

After you have the correct Date, format with Intl.DateTimeFormat or your UI library. See also the guide on JavaScript date formatting with Intl.DateTimeFormat on this site.
Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs …