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>

🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › date-add-days
JavaScript Add Days to Date - Mastering JS
const now = new Date(); // Add 37 days to now, and zero out hours, minutes, seconds, milliseconds now.setDate(now.getDate() + 37); now.setHours(0, 0, 0, 0); Working with JavaScript dates can be inelegant because most date methods return timestamps, not dates, so chaining isn't possible.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-days-to-date-in-javascript
How to Add Days to Date in JavaScript? - GeeksforGeeks
July 23, 2025 - The setDate() method allows you to modify the day of the month for a Date object. To use this method, you start by creating a Date object that represents the current date. You can then add a specific number of days to this date and assign the result to a new Date object.
🌐
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 the setDate() method which automatically handles month boundaries, year transitions, and leap years. This native JavaScript method eliminates edge case bugs that plague manual date arithmetic.
🌐
Full Stack Express
fullstackexpress.io › c › how-to-add-days-to-a-date-object-in-javascript
How to Add Days to a Date Object in JavaScript | Full Stack Express
const addDays = (date, days) => { const newDate = new Date(date); newDate.setDate(newDate.getDate() + days); return newDate; }; If we directly call the setDate() method on our date object, then the date would be mutated.
🌐
Futurestud.io
futurestud.io › tutorials › add-days-to-a-date-in-javascript-or-node-js
Add Days to a Date in JavaScript or Node.js
/** * Returns a date instance with added `days`. * * @param {Number} days - the number of days to add * @param {Date} date - the date adding the given `days` * * @returns {Date} */ function addDays (days, date = new Date()) { date.setDate(date.getDate() + days) return date } Also, a nice part of JavaScript’s setDate function is the automatic handling of the month and year changes. For example, when adding a day to August 31st you’re receiving September 1st.
Find elsewhere
🌐
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. Here is a utility function that creates a date object and adds seven days to it, to have a date object representing next week.
🌐
The Valley of Code
thevalleyofcode.com › how-to-add-days-date-javascript
How to add days to a date in JavaScript
Working with dates in JavaScript is always kind of fun. I wrote on this topic countless times, but there’s always more to learn. ... Today I have the solution to this problem: you have a Date object in JavaScript, and you want to add some days to it.
🌐
DEV Community
dev.to › hugo__df › add-days-to-a-date-in-vanilla-javascript-4p2l
Add days to a Date in vanilla JavaScript - DEV Community
May 3, 2019 - While it would be very easy to reach for moment.js or another date manipulation library (date-fns, luxon, dayjs) to do something as simple as adding days to a Date in JavaScript, writing a short helper function might just be easier. function addDays(date, days) { const copy = new Date(Number(date)) copy.setDate(date.getDate() + days) return copy } const date = new Date(); const newDate = addDays(date, 10); const date = new Date(); date.setDate(date.getDate() + 10); This actually works as expected, eg.
🌐
Code with Hugo
codewithhugo.com › add-date-days-js
Add days to a Date in vanilla JavaScript · Code with Hugo
May 1, 2020 - While it would be very easy to reach for moment.js or another date manipulation library (date-fns, luxon, dayjs) to do something as simple as adding days to a Date in JavaScript, writing a short helper function might just be easier. ... function addDays(date, days) { const copy = new Date(Number(date)) copy.setDate(date.getDate() + days) return copy } const date = new Date(); const newDate = addDays(date, 10); const date = new Date(); date.setDate(date.getDate() + 10); const date = new Date(); date.setDate(date.getDate() + 1); const date = new Date(); date.setDate(date.getDate() + 7); This actually works as expected, eg.
🌐
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. if ...
🌐
Knack
forums.knack.com › ask the community › get answers
JS problem with adding dates dates to all months with 31 days - Get Answers - Knack Community Forum
February 5, 2024 - I am trying to take in a date and get the Javascript to verify which quarter that date is in then output the date 1st day of the next quarter. My code works except for when someone enters the last day of the month on dates that end on the 31st. I figured out this may have something to do with timezones so I get UTC values instead of actual values so I remove the timezone out of the equation.
🌐
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 - // Creates a Date object with January 1, 2023, 00:00:00 let date1 = new Date(2023, 0, 1); // Creates a Date object with January 11, 2023, 00:00:00 let date2 = new Date(2023, 0, 11); console.log(date1.getTime()); // Output: "1672531200000" console.log(date2.getTime()); // Output: "1673344800000" console.log(date1.getTime() < date2.getTime()); // Output: "true" (date1 is before date2) console.log(date1.getTime() > date2.getTime()); // Output: "false" (date1 is not after date2) console.log(date1.getTime() === date2.getTime()); // Output: "false" (date1 is not equal to date2) One of the challenges
🌐
DEV Community
dev.to › lavary › how-to-add-days-to-a-date-in-javascript-without-a-library-3795
How to add days to a date in JavaScript (without a library) - DEV Community
February 5, 2023 - To add a few days to a date in JavaScript, you need to use setDate() on the Date object and increment the current day of the month by one or more days.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript add days to date
How to Add Days to Current Date in JavaScript | Delft Stack
February 2, 2024 - This tutorial will introduce how to add a new day to the current date or a custom date in JavaScript. We will first introduce what is Date and different methods in JavaScript Date class. In JavaScript, the Date class is basically the number of milliseconds that passed since midnight on January 1, 1970, UTC. It is not ...