1

I have a form that I need to calculate the difference in minutes between the current date and time and the user selected (future) date and time, but it doesn't seem to work:

form.addEventListener('submit', function (e) {
    e.preventDefault()
    currentDate.value = new Date().toLocaleString()
    delay.value = toMinutes((Date.parse(scheduled.value) - Date.now())/1000)
    localStorage.message = '{"recip": "' + recip.textContent + '", "msg": "' + msg.value + '", "sender": "' + sender.textContent + '"}'
    this.submit()
})

FYI: I'm a newbie here and newbie to javascript so apologies if i haven't provided enough info.

Mr Fisher
  • 17
  • 5
  • 1
    Does this answer your question? [How to calculate date difference in JavaScript?](https://stackoverflow.com/questions/7763327/how-to-calculate-date-difference-in-javascript) – OldProgrammer Dec 13 '21 at 18:10
  • Define "*doesn't seem to work*". `Date.parse(scheduled.value)` is rarely a good idea, see [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results). What is the value of *scheduled.value*? – RobG Dec 14 '21 at 00:25
  • You aren't getting any answers because you haven't provided enough information. You need to post a [*minimal* example](https://stackoverflow.com/help/minimal-reproducible-example) that demonstrates the issue (cut the HTML and script to absolute minimum: no CSS, etc.) and post it as a runnable snippet. Then provide sample input, expected output and actual output, along with any errors. Otherwise the question will likely be closed as "Needs detail or clarity". – RobG Dec 14 '21 at 03:35

0 Answers0