Calculate Time difference between two times
I found this code from try67. It is not working.
I have an ArrivalTime and DepartureTime they are set us as a time field, format h:MM tt (since this works best for users) I have the TimeOnJob field formatted to None.
Should I change the format on my two time entryfields?
Change the field's Format to None and use this code for the calculation (this is for the A row):
var cStart = this.getField("Start1").value;
var cStop = this.getField("Stop1").value;
if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60*60);
var totalHours = Math.floor(total);
var totalMinutes = (total-totalHours)*60;
var totalHoursString = (totalHours<10) ? "0"+totalHours : ""+totalHours;
var totalMinutesString = (totalMinutes<10) ? "0"+totalMinutes : ""+totalMinutes;
event.value = totalHoursString + totalMinutesString;
}
else {
event.value = ""
