-1
function AgregarDias(date, days) {
    var result = new Date(date);
    var dateFormated = result.toISOString().substr(0,10);
    //dateFormated.setDate(dateFormated.getDate() + days);
    return dateFormated;
}   

Any ideas, i've tried with too much ways

4 Answers4

1

Try using:

result.setDate(result.getDate() + days)

Hope that helped you :)

1

This should work:

function AgregarDias(date, days) {
    var dateFormated = new Date(date);
    dateFormated.setDate(dateFormated.getDate() + days);
    return dateFormated.toISOString().substr(0,10);
}

I am not sure why you are doing:

var dateFormated = result.toISOString().substr(0,10);

You should be able to work directly with the new Date object.

bmartin
  • 675
  • 5
  • 12
  • Ok, if you want to format the Date, you will first need to transform the date like above, then format it after the new date has been calculated. – bmartin Sep 02 '16 at 19:36
0

You can do it like this:

function AgregarDias(date,days) {
   var dateAdded = new Date(date);
   dateAdded.setDate(dateAdded.getDate() + days);
   return dateAdded;
}   
var datecustom = AgregarDias('2016-09-02',5);
alert(datecustom);
Dranes
  • 156
  • 10
0
function AgregarDias(date, days) {
    var newDate = new Date(date.setTime( date.getTime() + days * 86400000 ));
    console.log(newDate);
    return newDate;
}

AgregarDias(new Date(), 1);
Jitesh Sojitra
  • 3,655
  • 7
  • 27
  • 46