The question is simple, how can I add days to a date in YYYY-MM-DD format?
For example, increment a date given in this format: "2013-02-11" to "2013-02-12"?
The question is simple, how can I add days to a date in YYYY-MM-DD format?
For example, increment a date given in this format: "2013-02-11" to "2013-02-12"?
date = new Date('2013-02-11');
next_date = new Date(date.setDate(date.getDate() + 1));
here's a demo http://jsfiddle.net/MEptb/
Something like this :
var date = new Date('2013-02-11');
/* Add nr of days*/
date.setDate(date.getDate() + 1);
alert(date.toString());
I hope it helps.
Hope below code will helpful to you
function addDays(myDate,days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}
var myDate = new Date('2013-02-11');
var newDate = addDays(myDate,5);
Below function is to Add number of days to today's Date It returns the Incremented Date in YYYY-MM-DD format @param noofDays - Specify number of days to increment. 365, for 1 year.
function addDaysToCurrentDate(noofDays){
date = new Date();
next_date = new Date(date.setDate(date.getDate() + noofDays));
var IncrementedDate = next_date.toISOString().slice(0, 10);
console.log("Incremented Date " +IncrementedDate );
return IncrementedDate;
}
With the date parameter you can add your required date and you can add days with the addDays()
function:
var start_date = new Date('2013-02-11');
var next_date_update = addDays(start_date,1);
var next_date = new Date(next_date_update).toLocaleDateString('en-CA');
if(next_date!='Invalid Date')
{
var final_date = next_date;
console.log(final_date);
}
function addDays ( myDate , days)
{
return new Date(myDate.getTime() + days*24*60*60*1000);
}
hope it will help you out