0

I want to ask how to make a function javascript reactjs calculate the date and month of the year automatically with a distance of 10 days from 17-10-2020, after calculating from 17-10-2020 it will be like this 27-10-2020

Aniket Kariya
  • 1,471
  • 2
  • 21
  • 26
putra irawan
  • 822
  • 1
  • 7
  • 13

1 Answers1

2

This function should work:

const tenDaysInFuture = date => {
    const newDate = new Date(date);
    newDate.setDate(date.getDate() + 10);
    return newDate;
}

console.log(tenDaysInFuture(new Date('2020-09-29')));
console.log(tenDaysInFuture(new Date('2020-09-09')));
console.log(tenDaysInFuture(new Date('2020-10-17')));
TKoL
  • 13,158
  • 3
  • 39
  • 73