javascript number of seconds between two timestamps code example
Example 1: javascript get seconds between two dates
var secondBetweenTwoDate = Math.abs((new Date().getTime() - oldDate.getTime()) / 1000);
Example 2: javascript time between two times
You can just subtract the hours right away doing it this way
var valuestart = $("select[name='timestart']").val();
var valuestop = $("select[name='timestop']").val();
var timeStart = new Date("01/01/2007 " + valuestart).getHours();
var timeEnd = new Date("01/01/2007 " + valuestop).getHours();
var hourDiff = timeEnd - timeStart;
Here's the working fiddle http://jsfiddle.net/VnwF7/4/
UPDATE - to calculate if we are including the next day. Just add the following if block
if (hourDiff < 0) {
hourDiff = 24 + hourDiff;
}
http://jsfiddle.net/gfvhqat9/