JSFiddle - React, Tailwind, and code Playground

by frogggeee McFrogggeee

JavaScript

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