Avatar of ITsolutionWizard
ITsolutionWizard
Flag for United States of America asked on

JS Add Date

Inside of result var. I want to add days. like showing 01/01/2020
How can i do that in JS?

<script>
    window.addEventListener("load", function () {
        // target input
        picker.attach("arrivaldate");
        picker.attach("departuredate");
        let today = new Date().toLocaleDateString();
        var result = new Date().toLocaleDateString().toString("MM/dd/YYYY");
         
        //alert(date.addDays(5));
        this.document.getElementById("arrivaldate").value = today;
        this.document.getElementById("departuredate").value = result;

    });
  
</script>

Open in new window

JavaScript

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Ryan Chong

in order to use:

date.addDays(5)

Open in new window


you need to include this function as well:

Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}

Open in new window

ITsolutionWizard

ASKER
Just tried and not working to me
Ryan Chong

what error you have received?

what library you're using for your picker class?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.