If the times are in the format specified, you can get the difference in minutes using:
function diffMins(t0, t1) {
t0 = t0.split(':');
t1 = t1.split(':');
return t1[0]*60 + +t1[1] - t0[0]*60 - +t0[1]
}
That can be turned into decimal hours using:
function minsToHours(mins) {
return (mins/60).toFixed(2);
}
alert(minsToHours(diffMins('17:00', '23:45'))); // 6.75
If you want to get the difference in decimal hours for Date objects, then:
function dateDiffInHours(d0, d1) {
return ((d1 - d0) / 3.6e6).toFixed(2)
}
alert( dateDiffInHours( new Date(2012,07,02,17), new Date(2012,07,02,23,45))); // 6.75
Please note that passing a string to the Date object is not a good idea. While most browsers will parse one or two formats, some won't. There is no standard format specified in ESCMA-262 ed 3, parsing of date strings is completely implementation dependent. ES5 specifies a modification of the ISO8601 extended format (e.g. 2012-07-02T23:45:00Z), but a good percentage of browsers in use don't support it.
So always parse the string yourself, or call the constructor using arguments per the ECMAScript specification.