Home › Forums › Quform WordPress › Decimal Time Calculation › Reply To: Decimal Time Calculation
Hi,
I am trying to do something similar to this, please help me with the code.
The user will select start time (1_6) and end Time (1_7), upon selection I want a field (1_50) to display total hours requested just like above but I want to add 12 hours if PM
jQuery(function ($) {
function convertTimeToMinutes(time) {
var parts = time.split(‘:’);
//if PM add 12 hours ???
return (60 * parseInt(parts[0], 10)) + parseInt(parts[1], 10);
}
// Number of hours requested
$(‘.quform-field-10_6, .quform-field-10_7’).on(‘change blur’, function () {
var start = $(‘.quform-field-1_6’).val(),
end = $(‘.quform-field-1_7’).val(),
total = 0;
if (start && end) {
start = convertTimeToMinutes(start);
end = convertTimeToMinutes(end);
total = (end – start) / 60;
}
$(‘.quform-field-1_50).val(total);
});
});