Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag 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

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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

Avatar of ITsolutionWizard

ASKER

Just tried and not working to me
what error you have received?

what library you're using for your picker class?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial