JavaScript

Add days to javascript date

In the javascript, we can simply add days to the existing date.

In addition to methods to read and alter individual components of the local date and time (such as getDay() and setHours()), there are also versions of the same methods that read and manipulate the date and time using UTC (such as getUTCDay() and setUTCHours()).

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

var date = new Date();

alert(date.addDays(5));

you can simply modify that code as per requirement.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button