Click here to Skip to main content
16,020,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript

I have two datetime input fields (today's date and exam date) and i would like to display the time difference between the two user inputs in my alert JavaScript box for only 5 seconds.

So far i can only display my three variables module code, today's date and exam date.
I cant seem to get the code right,

like changing value="2017-10-22T10:00:00" into miliseconds
the datetime format is making it hard for me to convert to miliseconds

What I have tried:

<form class="form">

<label><b>Module Code</b></label> <br>
<input id="f1" name="module" type="text" autofocus required placeholder="Module Code"><br>

<label><b>Today's Date</b></label> <br>
<input name="time_start" type="datetime-local" id="f2" placeholder="Select" value="2017-10-22T10:00:00"><br>

<label><b>Exam's Date</b></label> <br>
<input name="time_end" type="datetime-local" id="f3" placeholder="Select" value="2017-10-30T10:00:00"><br>

<button type="submit" class="signupbtn" onClick="processData('f1','f2','f3')">Calculate</button>

</form>





function processData(f1,f2,f3)
{
var module = document.getElementById(f1).value;
var time_start = document.getElementById(f2).value;
var time_end = document.getElementById(f3).value;
alert(module + "\n" + time_start + "\n" + time_end);
}
Posted
Updated 25-Oct-17 4:08am

1 solution

Use moment.js[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900