I need to make a function that takes a string and x number (subDays) of days as arguments and convert the string to a date and subtracts the x number of days from the date.
The input string is in format (YYYY-MM-DD) and I would like to get the same format back.
I get an Invalid Date
error.
function newDate(date, subDays) {
var myDate = new Date(date);
myDate.setDate(myDate -subDays);
console.log("Date: " + myDate);
}