moment.js does not take user input

  javascript, momentjs, parsing

Moment.js returns NaN when I attempt to subtract time from given race start date to time of finishing the race. My code is below. I am looking to get the results in minutes. For instances if the user inputs "01-02-2021 08:00 AM " It should return 1440 minutes. Any suggestions ?

let startTime = moment('01-01-2021 08:00 AM');
let endingTime = moment(document.getElementById('arrival').value);
let minuteCount = endingTime.diff(startTime, 'minutes'); 




document.getElementById("myBtn").addEventListener("click", function() {
    document.getElementById('result').innerHTML = minuteCount;
});

console.log(minuteCount);

Source: Ask Javascript Questions

LEAVE A COMMENT