function futureDay(inputDate, days) {
// Create a new Date object based on the input date
var nextDay = new Date(inputDate);
// Increment the date by one day
nextDay.setDate(nextDay.getDate() + days);
// Return the date that is one day later
var year = nextDay.getFullYear();
var month = ('0' + (nextDay.getMonth() + 1)).slice(-2); // Adding 1 because getMonth() returns zero-based month
var day = ('0' + nextDay.getDate()).slice(-2);
// Concatenate components into a string in the format "YYYY-MM-DD"
var dateString = month + '/' + day + '/' + year;
// Return the formatted date string
return dateString;
}
// Example usage:
var inputDate = new Date('2022-03-26'); // March 26, 2022
var nextDate = futureDay(inputDate, 9);
console.log(nextDate); // Output: Date object representing March 27, 2022
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.