Difference Between Start time and Finish time in Form
Hi Guys,
I currently working on a timesheet that Calculates the difference between start and end time.
this is the code I have so far.
// start
var start = this.getField("StartRow1").value;
var startArr = start.split(":");
// finish
var finish = this.getField("FinishRow1").value;
var finishArr = finish.split(":");
// difference
var hourDiff = Math.abs(finishArr[0] - startArr[0]);
var minDiff = Math.floor((Math.abs(finishArr[1] - startArr[1]) / 59)*100);
if (minDiff.toString().length == 1)
minDiff = '0' + minDiff;
var output = hourDiff + "." + minDiff;
event.value = output;
the problem is that when no start and end time is entered into the columns I get a 0.NaN. I don't want this to show. I want to total hours cell to be blank if I have not inserted any start and finish times. at the moment the table below represents what the code is giving me. I need a script that will give an empty cell if nothing in inserted.
thanks
| Start | End | Total Hours |
|---|---|---|
| 9:00 | 17:00 | 8.00 |
| 0.NaN | ||
| 0.NaN |