There are several different ways to perform time calculations. The simplest is to parse the time format, subtract the parts, and then reformat. This method depends on the hours always being in the same day. If the hours cross midnight, then a modification is needed. If the times cover several days, then a more complicated technique is required.
So here's the simple bit, I just made up form field names. You'll need to modify this script to match the fields on your form.
Place this code into the calculation script for the "Working Hours" field
// Set Default
event.value = "";
var rgTimeParse = /^\s*(\d{1,2})\:(\d{2})\s*$/;
var strStart = this.getField("StartTime").valueAsString;
var strEnd = this.getField("EndTime").valueAsString;
if(rgTimeParse.test(strStart)){
var nStart = Number(RegExp.$1) + Number(RegExp.$2)/60;
if(rgTimeParse.test(strEnd)){
var nEnd = Number(RegExp.$1) + Number(RegExp.$2)/60;
var nTimeTotal = nEnd - nStart;
var nHours = Math.floor(nTimeTotal);
event.value = util.printf("%02d:%02d",nHours , (nTimeTotal-nHours)*60);
}
}
... View more