2 Replies Latest reply on Mar 3, 2008 5:09 PM by (Irfan_Asrar)

    how to add hours worked

      Hi There,

      I have a relatively simple problem, I am taking the hours in two text fields.

      HH:MM (Field 1)

      HH:MM (Field 2)

      and adding them to calculate the total hours worked, cant seem to get it working. I am able to calculate the difference but unable to add them,
      any help would be appreciated.

        • 1. Re: how to add hours worked
          gkaiseril MVP & Adobe Community Professional
          You will have to split the hours minutes from the formatted field and convert the hours to minutes. Then add all the minute values together to get the total minutes. Now you will have to get the whole hours and the remaining minutes and then format the result.

          function PFNHrsMinToMin(sTime) {
          var aTime = sTime.split(":"); // split into hours and minutes
          return (1*aTime[0]* 60) + 1*aTime[1]; // return time string as minutes

          var Day1 = this.getField("Day1Worked").value
          var Day2 = this.getField("Day1Worked").value
          var Day3 = this.getField("Day1Worked").value
          var Day4 = this.getField("Day1Worked").value
          var Day5 = this.getField("Day1Worked").value
          var minWorked = PFNHrsMinToMin(Day1) + PFNHrsMinToMin(Day2) + PFNHrsMinToMin(Day3) + PFNHrsMinToMin(Day4) + PFNHrsMinToMin(Day5);
          event.vlaue = Math.floor(minWorked/60) + ":" + util.printf("%,002d",(minWorked % 60)); // split hours and minutes and format
          • 2. Re: how to add hours worked
            Level 1
            Thanks a million Geo, that worked great...