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));



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s