javascript – How to add number of days to todays date?

javascript – How to add number of days to todays date?

You can use JavaScript, no jQuery required:

var someDate = new Date();
var numberOfDaysToAdd = 6;
var result = someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
console.log(new Date(result))

This is for 5 days:

var myDate = new Date(new Date().getTime()+(5*24*60*60*1000));

You dont need JQuery, you can do it in JavaScript, Hope you get it.

javascript – How to add number of days to todays date?

You could extend the javascript Date object like this

Date.prototype.addDays = function(days) {
    this.setDate(this.getDate() + parseInt(days));
    return this;
};

and in your javascript code you could call

var currentDate = new Date();
// to add 4 days to current date
currentDate.addDays(4);

Leave a Reply

Your email address will not be published.