In JavaScript, how can I calculate the difference between two times that are in 24 hour format?
Example: Get how many hours elapsed from 08:00:00 to
You dont need to convert them into dates for this specific case. Just Do this
$(document).ready(function() {
function calculateTime() {
var hourDiff =
parseInt($("select[name='timestart']").val().split(':')[0],10) -
parseInt($("select[name='timestop']").val().split(':')[0],10);
$("p").html("Hour Difference: " + hourDiff )
}
$("select").change(calculateTime);
calculateTime();
});
Working fiddle