4 Replies Latest reply on Aug 11, 2016 6:11 AM by gkaiseril

    calculate travel times in am and pm

    nick Lowe

      I am using this script to calculate Travel times.  It works for morning hours but not or afternoon or PM hours. Any suggestions.

       

      // start
      var start = this.getField("StartTime").value;
      var startArr = start.split(":");

      // finish
      var finish = this.getField("FinishTime").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;