Increment date by any number using js


This is the function to do so:

function increment_date(date,increment)
{
var dateString = date;
var myDate = new Date(dateString);
myDate.setDate(myDate.getDate() + increment);
var y = myDate.getFullYear(),
m = myDate.getMonth() + 1, // january is month 0 in javascript
d = myDate.getDate();
var pad = function(val) { var str = val.toString(); return (str.length < 2) ? “0” + str : str};
dateString = [y, pad(m), pad(d)].join(“/”);
return dateString;
}

 

and here is the example for that:

date_val = increment_date(‘2014/05/29’,parseInt(1));