Discovering Typescript for the first time, I'm attempting to calculate a date that is (X) months or days from now and format it as newDate
below...
When trying to add one month:
const dateObj = new Date();
const month = dateObj.getUTCMonth() + 2;
const day = dateObj.getUTCDate();
const year = dateObj.getUTCFullYear();
const newDate = `${month}/${day}/${year}`;
The result shows:
13/6/2022
Attempting to add 30 days instead:
const dateObj = new Date();
const month = dateObj.getUTCMonth() + 1;
const day = dateObj.getUTCDate() + 30;
const year = dateObj.getUTCFullYear();
const newDate = `${month}/${day}/${year}`;
This results in:
12/36/2022
The example not only provides incorrect month & day values but also fails to advance the year.
Any suggestions?