I would like to calculate time difference based on dynamic id from 2 text-fields and display it on third.
My current code:
function mdiff(t1,t2) {
var t1 = hour2mins(t1); var t2=hour2mins(t2);
var ret = mins2hour(parseInt(t2-t1));
if(t2<t1) {
ret=mins2hour(parseInt(parseInt(t2+1440)-t1));
}
return ret;
}
$("input.[rel=diff]").keyup(function (b){
$("#duration").val(mdiff($("#starttime).val(),$("#endtime").val()));
});
I am using trent’s timepicker addon in my code to generate time. How can I calculate the difference?
You can use the ‘onSelect’ event for the ‘timepicker’ Object like in the example below:
Yes, that’s true. I missed the ‘Add’ button and these selectors were meant to work for one row. Here is an update of the previous code:
UPDATE: — “is there a way to make this code work when users enters time manually ?”
Inside $(document).ready(); you’ll have to add an ‘onblur’ event for the timepicker input.
Here is an example: jsFiddle