Calculating time for nightshift timesheet
Hi all, I received help previously for a script to calculate duration between 2 times, however it doesn't work if we have nightshift times (i.e. from 10pm to 5am). If anyone could help to adjust it for nightshift that would be appreciated. Here is the current script and the form:
if ((this.getField("End TimeRow1").value.length == 0) || (this.getField("Start TimeRow1").value.length == 0)) {
event.value = " 0 Hours 0 Minutes";
}
else{
var timefinished = this.getField("End TimeRow1").value;
var timestarted = this.getField("Start TimeRow1").value;
var datetimefinished = new Date('1970/01/01' + " " + timefinished);
var datetimestarted = new Date('1970/01/01' + " " + timestarted);
var difflnMilliSeconds = Math.abs(datetimefinished - datetimestarted)/1000;
var hours = Math.floor(difflnMilliSeconds / 3600) % 24;
difflnMilliSeconds -= hours *3600;
var minutes = Math.floor(difflnMilliSeconds / 60) % 60;
difflnMilliSeconds -= minutes * 60;
event.value = hours + (minutes/60) ;
}

