5 Replies Latest reply on Mar 8, 2017 12:40 PM by gkaiseril

    time sheet Calculate time


      I am trying to calculate Total Hours in a Time sheet I created in Acrobat Pro. I found the script online to calculate hours between In and Out for the day but I am having two issues.


      1. If time is not entered in military format then the total for that day is incorrect. As long as I enter military format it gives me correct total.
        1. As you can see in line one in below screenshot I am getting correct total.
        2. Line two however is giving me -4:00 because my clock in time after lunch is 12:00 and out is 5:00.
        3. Line 3 shows time entered as military time.
      2. Issue number two. After I get the totals for each day in a time format then how to I add them up to get the total for the week?
        1. If I simply add the fields I get incorrect result. I am guessing because I am trying to add time which isn't same as decimal number.



      This is the script I have in the total box for the day (T1). I have used same code for the remaining day totals and simply change the field names.

      ------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------

      var nElapsed = ((this.getField("OutRow1").value * 60) + this.getField("OutRow1min").value) - ((this.getField("InRow1").value * 60) + this.getField("InRow1min").value)+

      ((this.getField("OutRow1_2").value * 60) + this.getField("OutRow1_2min").value) - ((this.getField("InRow1_2").value * 60) + this.getField("InRow1_2min").value);


      // elapsed hours;

      var nHrs = Math.floor(nElapsed / 60); // whole hours;

      // elapsed minutes

      var nMins = nElapsed % 60; // remainder minutes;

      // format into hours and minutes;

      event.value = util.printf("%,101.0f:%,102.0f", nHrs, nMins);

        • 1. Re: time sheet Calculate time
          gkaiseril MVP & Adobe Community Professional

          Have you tired to do the calculations by hand?


          11:00 less 8:00 would be 660 - 480 or 180 minutes (3 hours 0 minutes)


          5:00 less 12:00 would be 300 - 720 or - 420 minutes (-7 hours 0 minutes)


          Then 180 + (-420) would be -240 minutes (-4 hours0 minutes)


          You have to specify whether the hours are before or after Noon. The hours after 12:00pm are 12 hours after the same hours beform 12:00pm. If you were to add 720 (12 hours) to the 5:00 in the afternoon, you would have the correct answer. You need to be able to tell the difference between times before 12:00pm and times after 12:00pm.


          Have you looked at using the time format of "hh:MMtt" and using the JavaScript Date object to obtain the minutes since the Epoch date for the 2 time intervals? You will need to provide the date to get the correct results. This approach will also adjust correctly for Day Light Savings time if needed.

          • 2. Re: time sheet Calculate time
            JR_Boulay Adobe Community Professional



            Instead of reinventing the wheel you should search "Time sheet" on this forum, there are some nice examples to download around here.


            • 3. Re: time sheet Calculate time
              try67 MVP & Adobe Community Professional

              If you're interested I've developed a tool that allows you to set up exactly this kind of calculations very easily: Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

              • 4. Re: time sheet Calculate time
                matures29785352 Level 1

                I was able to get the time to calculate somewhat based on sample time sheet I found on this website but still need help.


                I have uploaded my time sheet sample to Drop Box - https://www.dropbox.com/s/ic22gs7rx1h8ny4/Test_Payroll_Sheet.pdf?dl=0


                1. First scenario shows I am using two extra fields to calculate total hours since I could not figure out how to do that with Javascript.
                2. Second scenario shows that I was able to figure out calculation for first in/out group then not sure how to add the after break time.
                3. Third shows that if someone enters start time and skips to out and leave the two boxes in between empty the calculation doesn't work. We have people who do this all the time.


                Any help is appreciated.

                • 5. Re: time sheet Calculate time
                  gkaiseril MVP & Adobe Community Professional

                  One can use the JavaScript variable statement to hold the results of intermediate calculations or to accumulate the intermediate results until the final result can be computed. Using this approach eliminates the need to use fields to hold the intermediate results.


                  For scenario three, you need to decide how to handle this situation. In the samples I have posted I do not compute the result for a pair on in and out times unless the start and end times are present. I chose to not add the additional code to verify that all the pairs of entries are added. Most employers do not process timesheets that are not properly completed. If one were to leave the start or end times empty the calculations will tread the empty time value as if it were midnight of the day or if the day were also missing then date and time is assumed to be Midnight January 1, 1970 or the Epoch date for the scripting language and Operating System being used.


                  Your calculations will work properly if the time interval you are trying to compute includes the time period when there is the change of time for the ending of daylight savings time or summer time.