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>

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-days-to-date-in-javascript
How to Add Days to Date in JavaScript? - GeeksforGeeks
July 23, 2025 - You can then add a specific number ... Example: This example we defines a function addDays to add a specified number of days to a date, then applies it to the current date, and logs the new date....
🌐
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 - To add days to date with JavaScript you can use the setDate method adding the number of days to the date (or current date). Below are two examples of adding 7 days to today and a date in the past:
🌐
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, ...
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-add-days-to-current-date-in-javascript.php
How to Add Days to Current Date in JavaScript
Similarly, you can also add number of days to a particular date in JavaScript. ... // Specific date var date = new Date('August 21, 2021 16:45:30'); // Add ten days to specified date date.setDate(date.getDate() + 10); console.log(date);
🌐
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
🌐
W3docs
w3docs.com › javascript
How to Add Days to JavaScript Date
... const date = new Date(); const theDayOfTheMonthOnNextWeek = date.getDate() + 7; date.setDate(theDayOfTheMonthOnNextWeek) console.log(date); ... The Date is a built-in object in JavaScript.
🌐
CoreUI
coreui.io › answers › how-to-add-days-to-date-in-javascript
How to add days to date in JavaScript · CoreUI
September 30, 2025 - When you call date.getDate() + 7, it adds 7 days to the current day of the month. If this exceeds the month’s length, JavaScript automatically rolls over to the next month and adjusts the year if necessary.
Find elsewhere
🌐
Medium
medium.com › @gaelgthomas › add-one-day-to-date-in-javascript-6b7d98b0edce
Add One Day to Date in JavaScript | by Gaël Thomas | Medium
December 21, 2022 - The best way to add 1 day to a JavaScript date is by using the Date object. On an existing Date, you can use the getDate function to get the day (between 1 and 31), add 1 to this number, then use
🌐
Attacomsian
attacomsian.com › blog › javascript-date-add-days
How to add days to a date in JavaScript
September 10, 2022 - For example, to add one day to the current date, use the following code: const today = new Date(); const tomorrow = new Date() // Add 1 Day tomorrow.setDate(today.getDate() + 1) To update an existing JavaScript Date object, you can do the following: ...
🌐
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 - 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
🌐
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!
🌐
TutorialsPoint
tutorialspoint.com › how-to-add-number-of-days-to-javascript-date
How to add number of days to JavaScript Date?
<!DOCTYPE html> <html> <head> <title>Example- add number of days to the Date object</title> </head> <body> <h2> Add Number of days to the JavaScript Date object using setDate( ) method </h2> <p> Click on the button to add 2 days to the current date/time.</p> <button onclick="add()">Click ...
🌐
Day.js
day.js.org › docs › en › manipulate › add
Add · Day.js
result = dayjs().add(dayjs.duration({'days' : 1}))
🌐
W3Schools
w3schools.com › js › tryit.asp
JavaScript Dates
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
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 - For example, if you add one day to January 1, 2023, 00:00:00 in IST, you will get January 2, 2023, 00:00:00 in IST. However, if you add one day to January 1, 2023, 00:00:00 in UTC, you will get January 1, 2023, 19:00:00 in IST, which is still ...
🌐
JSFiddle
jsfiddle.net › taditdash › 8FHwL
[Demo] Add Days to a Date in JavaScript - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
🌐
10xdev
10xdev.blog › howto-add-days-dates-javascript
How to add days to dates in JavaScript | Techiediaries
Call the JavaScript’ setDate() method, and passing as a parameter the result of calling getDate() plus the number of days you need to add. The setDate() method takes care of adding the wanted number of days to the Date object. Let’s take a simple example of adding 1 day to a date:
🌐
Codú
codu.co › articles › add-days-to-a-date-in-javascript-rfnfso00
Add Days to a Date in JavaScript | by Niall Maher | Codú
Adding days to a date in JavaScript is fairly easy using the Date object. You can update a date using the .setDate() method. Here's how: