I have a date1 and I want to add interval to it and return new date as date2:
const newInterval = 1;
const date1 = '2022-03-02T19:16:51.433Z';
const currentDue = new Date(date1);
const date2 = new Date(new Date().setDate(currentDue.getDate() + newInterval));
console.log(date2);
As you see my date2 format is not same as date1 format and I need to return the date2 with exact format same as the date1!!
So the desired result of date2 would be:
'2022-03-03T19:16:51.433Z';
How can I do this?
Simply create a new date from the original date and add the interval to that:
const newInterval = 1;
const date1 = '2022-03-02T19:16:51.433Z';
const currentDue = new Date(date1);
const date2 = new Date(currentDue.setDate(currentDue.getDate() + newInterval));
console.log(date2)