Skip to main content
Addeded code snippet so people could see live answer and test compatibility.
Source Link

The simplest solution.

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

and then call

var newDate = new Date().addDays(2); //+2 days 

or

 Date.prototype.addDays = function(days) { this.setDate(this.getDate() + parseInt(days)); return this; }; // and then call var newDate = new Date().addDays(2); //+2 days console.log(newDate); // or var newDate1 = new Date().addDays(-2); //-2 days console.log(newDate1);
var newDate = new Date().addDays(-2); //-2 days 
 

The simplest solution.

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

and then call

var newDate = new Date().addDays(2); //+2 days 

or

var newDate = new Date().addDays(-2); //-2 days 

The simplest solution.

 Date.prototype.addDays = function(days) { this.setDate(this.getDate() + parseInt(days)); return this; }; // and then call var newDate = new Date().addDays(2); //+2 days console.log(newDate); // or var newDate1 = new Date().addDays(-2); //-2 days console.log(newDate1);
 

Source Link
ampachts
  • 155
  • 3
  • 6

The simplest solution.

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

and then call

var newDate = new Date().addDays(2); //+2 days 

or

var newDate = new Date().addDays(-2); //-2 days