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
  • 986
  • 2
  • 15
  • 20
putra irawan
  • 652
  • 1
  • 6
  • 11

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
  • 11,982
  • 1
  • 32
  • 61