You can create one using Date.prototype.setDate():

Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}

var date = new Date();

console.log(date.addDays(5));

This takes care of automatically incrementing the month if necessary, as noted here. For example:

8/31 + 1 day will become 9/1.

The problem with using setDate directly is that it's a mutator and that sort of thing is best avoided. ECMA saw fit to treat Date as a mutable class rather than an immutable structure.

Answer from AnthonyWJones on Stack Overflow
Top answer
1 of 16
1850

You can create one using Date.prototype.setDate():

Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}

var date = new Date();

console.log(date.addDays(5));

This takes care of automatically incrementing the month if necessary, as noted here. For example:

8/31 + 1 day will become 9/1.

The problem with using setDate directly is that it's a mutator and that sort of thing is best avoided. ECMA saw fit to treat Date as a mutable class rather than an immutable structure.

2 of 16
1171

Correct Answer:

function addDays(date, days) {
  var result = new Date(date);
  result.setDate(result.getDate() + days);
  return result;
}

Incorrect Answer:

This answer sometimes provides the correct result but very often returns the wrong year and month. The only time this answer works is when the date that you are adding days to happens to have the current year and month.

// Don't do it this way!
function addDaysWRONG(date, days) {
  var result = new Date(); // not instatiated with date!!! DANGER
  result.setDate(date.getDate() + days);
  return result;
}

Proof / Example

Check this JsFiddle

// Correct
function addDays(date, days) {
    var result = new Date(date);
    result.setDate(result.getDate() + days);
    return result;
}

// Bad Year/Month
function addDaysWRONG(date, days) {
    var result = new Date();
    result.setDate(date.getDate() + days);
    return result;
}

// Bad during DST
function addDaysDstFail(date, days) {
    var dayms = (days * 24 * 60 * 60 * 1000);
    return new Date(date.getTime() + dayms);    
}

// TEST
function formatDate(date) {
    return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
}

$('tbody tr td:first-child').each(function () {
    var (this);
    var ('<td/>').insertAfter($in).addClass("answer");
    var $outFail = $('<td/>').insertAfter(outDstFail = $('<td/>').insertAfter($outFail);
    var date = new Date($in.text());
    var correctDate = formatDate(addDays(date, 1));
    var failDate = formatDate(addDaysWRONG(date, 1));
    var failDstDate = formatDate(addDaysDstFail(date, 1));

    $out.text(correctDate);
    $outFail.text(failDate);
    $outDstFail.text(failDstDate);
    $outFail.addClass(correctDate == failDate ? "right" : "wrong");
    $outDstFail.addClass(correctDate == failDstDate ? "right" : "wrong");
});
body {
    font-size: 14px;
}

table {
    border-collapse:collapse;
}
table, td, th {
    border:1px solid black;
}
td {
    padding: 2px;
}

.wrong {
    color: red;
}
.right {
    color: green;
}
.answer {
    font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
    <tbody>
        <tr>
            <th colspan="4">DST Dates</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>03/10/2013</td></tr>
        <tr><td>11/03/2013</td></tr>
        <tr><td>03/09/2014</td></tr>
        <tr><td>11/02/2014</td></tr>
        <tr><td>03/08/2015</td></tr>
        <tr><td>11/01/2015</td></tr>
        <tr>
            <th colspan="4">2013</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2013</td></tr>
        <tr><td>02/01/2013</td></tr>
        <tr><td>03/01/2013</td></tr>
        <tr><td>04/01/2013</td></tr>
        <tr><td>05/01/2013</td></tr>
        <tr><td>06/01/2013</td></tr>
        <tr><td>07/01/2013</td></tr>
        <tr><td>08/01/2013</td></tr>
        <tr><td>09/01/2013</td></tr>
        <tr><td>10/01/2013</td></tr>
        <tr><td>11/01/2013</td></tr>
        <tr><td>12/01/2013</td></tr>
        <tr>
            <th colspan="4">2014</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2014</td></tr>
        <tr><td>02/01/2014</td></tr>
        <tr><td>03/01/2014</td></tr>
        <tr><td>04/01/2014</td></tr>
        <tr><td>05/01/2014</td></tr>
        <tr><td>06/01/2014</td></tr>
        <tr><td>07/01/2014</td></tr>
        <tr><td>08/01/2014</td></tr>
        <tr><td>09/01/2014</td></tr>
        <tr><td>10/01/2014</td></tr>
        <tr><td>11/01/2014</td></tr>
        <tr><td>12/01/2014</td></tr>
        <tr>
            <th colspan="4">2015</th>
        </tr>
        <tr>
            <th>Input</th>
            <th>+1 Day</th>
            <th>+1 Day Fail</th>
            <th>+1 Day DST Fail</th>
        </tr>
        <tr><td>01/01/2015</td></tr>
        <tr><td>02/01/2015</td></tr>
        <tr><td>03/01/2015</td></tr>
        <tr><td>04/01/2015</td></tr>
        <tr><td>05/01/2015</td></tr>
        <tr><td>06/01/2015</td></tr>
        <tr><td>07/01/2015</td></tr>
        <tr><td>08/01/2015</td></tr>
        <tr><td>09/01/2015</td></tr>
        <tr><td>10/01/2015</td></tr>
        <tr><td>11/01/2015</td></tr>
        <tr><td>12/01/2015</td></tr>
    </tbody>
</table>

🌐
W3Schools
w3schools.com › js › js_date_methods_set.asp
JavaScript Date Set Methods
Set Date methods let you set date values (years, months, days, hours, minutes, seconds, milliseconds) for a Date Object. Set Date methods are used for setting a part of a date: The setFullYear() method sets the year of a date object. In this example to 2020:
🌐
W3Schools
w3schools.com › js › js_dates.asp
JavaScript Dates
const d = new Date(2018, 11, 24, 10, 33, 30, 0); Try it Yourself » ... January = 0. December = 11. Specifying a month higher than 11, will not result in an error but add the overflow to the next year: ... Specifying a day higher than max, will not result in an error but add the overflow to the next month: ... You cannot omit month. If you supply only one parameter it will be treated as milliseconds. ... JavaScript stores dates as number of milliseconds since January 01, 1970.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-days-to-date-in-javascript
How to Add Days to Date in JavaScript? - GeeksforGeeks
July 23, 2025 - To add a specific number of days to a date, we first convert the days into milliseconds and then add them to the current date represented in milliseconds. This approach enables precise date manipulation in JavaScript.
🌐
W3docs
w3docs.com › javascript
How to Add Days to JavaScript Date
In this tutorial, you will learn an easy way of adding days to Javascript Date with setDate() and getDate() inbuilt functions to set and get the day of the month represented by the Date object.
🌐
W3Schools
w3schools.com › jsref › jsref_setdate.asp
JavaScript Date setDate() Method
Set the day to the first day in the next month: const d = new Date("2025-01-15"); d.setDate(32); Try it Yourself » · setFullYear() setMonth() setUTCDate() setUTCMonth() setUTCFullYear() Date.setDate(day) setDate() is an ECMAScript1 (JavaScript 1997) feature.
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
CoreUI
coreui.io › answers › how-to-add-days-to-date-in-javascript
How to add days to date in JavaScript · CoreUI
September 30, 2025 - The most reliable approach is using ... eliminates edge case bugs that plague manual date arithmetic. Use setDate() with getDate() to safely add days to any date....
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › date-add-days
JavaScript Add Days to Date - Mastering JS
const date = new Date('2022-06-01'); // June 1, 2022 UTC time date.setDate(date.getDate() + 30); // Add 30 days date; // July 1, 2022 UTC time · The setDate() function modifies the date object in-place and returns the new Unix timestamp as a number.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-add-days-to-current-date-in-javascript.php
How to Add Days to Current Date in JavaScript
You can simply use the setDate() method to add number of days to current date using JavaScript. Also note that, if the day value is outside of the range of date values for the month, setDate() will update the Date object accordingly (e.g.
🌐
Geshan
geshan.com.np › blog › 2022 › 07 › javascript-add-days-to-date
How to add days to a date in JavaScript (with code examples)
July 26, 2022 - Learn how to add days to date in JavaScript with native date object and date-fns NPM package in this tutorial.
🌐
Envato Tuts+
code.tutsplus.com › home › javascript
How to Add or Subtract Days (And More) From Dates in Vanilla JavaScript | Envato Tuts+
June 8, 2023 - This tutorial will teach you how to add or subtract years, months, days, hours, minutes, or seconds from a date in vanilla JavaScript. No libraries required!
🌐
W3Schools
w3schools.com › js › js_temporal_arithmetic.asp
JavaScript Temporal Date Arithmetic - Add and Subtract Dates Safely
Learn how to add and subtract dates safely using JavaScript Temporal. Perform date arithmetic without DST bugs or mutation problems. Temporal provides safe and clear methods for date arithmetic. You can add or subtract days, months, years, and more without modifying the original value.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Date Methods
The getDay() method returns the weekday of a date as a number (0-6). In JavaScript, the first day of the week (day 0) is Sunday. Some countries in the world consider the first day of the week to be Monday.
🌐
MSR
rajamsr.com › home › how to add days to date in javascript with 3 examples
How to Add Days to Date in JavaScript With 3 Examples | MSR - Web Dev Simplified
January 18, 2024 - Learn how to add days to a date using JavaScript in 3 different ways. Best code examples and explanations for beginners.
🌐
Code with Hugo
codewithhugo.com › add-date-days-js
Add days to a Date in vanilla JavaScript · Code with Hugo
May 1, 2020 - const d = new Date('2019-04-14'); const monthRollsOver = addDays(myDate, 31); console.log(monthsRollOver) // 2019-05-15 · Find the live examples at: observablehq.com/@hugodf/add-days-to-a-javascript-date
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › date › add minutes, hours or days to date
How can I add minutes, hours or days to a JavaScript date? - 30 seconds of code
January 5, 2024 - If a day is not a weekday, we will add or subtract another day, as needed, until we find a weekday. const isWeekday = date => date.getDay() % 6 !== 0; const addWeekDays = (date, n) => { const s = Math.sign(n); const d = new Date(date); return Array.from({ length: Math.abs(n) }).reduce((currentDate) => { currentDate = addDaysToDate(currentDate, s); while (!isWeekday(currentDate)) currentDate = addDaysToDate(currentDate, s); return currentDate; }, d); }; addWeekDays('2020-10-05', 5); // 2020-10-12 addWeekDays('2020-10-05', -5); // 2020-09-28