3 Replies Latest reply on Jan 13, 2014 6:43 AM by KT_2014

    Acrobat 9 STANDARD - Calculate Start/End Time

    KT_2014 Level 1

      I've spent a couple hours searching the Internet, trying to figure out how to Calculate Total Hours from "Time In" and "Time Out fields". I do not know how to write script, though I've tried copying (and making minor edits to) a few different ones I found online. I thought I came close to victory once or twice with a generated total, but then it wouldn't recreate the calculation with new input... so all I got out of that was blurry vision and a headache. I am very new at creating even basic forms (I taught myself from YouTube), so please go easy on me!




      I understand I have to format the Time in a certain way to allow a formula to calculate, then insert script for Time In/Out and Total.


      1. Does anyone have a script I could use for this?
      2. Where should I insert said script?(Custom format/Custom calculation?)
      3. How should I format Time fields?
      4. How on earth does anyone learn all this stuff?


      ***As I just learned, I do not have "document level functions" with Acrobat Standard.


      Any help/advice/scripts would be greatly appreciated!

        • 1. Re: Acrobat 9 STANDARD - Calculate Start/End Time
          gkaiseril MVP & Adobe Community Professional

          This is a very tricky problem. If you are running the timesheet for 24 a day coverage then you will need to write special keystroke and validation scripts to allow time from midnight to midnight since the provided time format only allows valid time entries for the day, from midnight to 11:59:59.999 pm or 23:59:59.999 since the next midnight would be the start of the next day.


          One has to convert the time string to a JS date object and for time that includes the date for the time or split the time string into hours and minutes and adjust the hours as needed for times after 12:59:59.999 pm. Once the hours and minutes are obtained, one converts to either the minutes to hours and decimal hours and adds to the hours for the time in hours only or the hours to minutes added to the minutes so the time is in minutes.


          Once all the times values have been reduced to a common unit the calculation is straight forward.


          The final step would be converting the total time from the common unit to the hours and minutes format or converting the time to hours and decimal hours.


          Since these calculations are repeated several times with just a value change it is possible to create functions to perform the conversion of the time strings to common unit value.


          When one realizes that a field can have a value but display that value in a different format, the totaling of the daily time worked can be simplified to a simple totaling operation.


          With Acrobat Standard the document level scripts can be placed in the open page action but if the PDF has more than one page one would want to add some script to only load the functions once.

          • 2. Re: Acrobat 9 STANDARD - Calculate Start/End Time
            gkaiseril MVP & Adobe Community Professional

            Here is a sample timesheet

            sample Time Sheet



            And the functions:


            function HHMM2Num(cFormat, cTime) {
            convert formatted (cFormat) time stirng (cTime) to date object based not the Eoch date;
            adjust the returned number of minutes to the number of minutes from that start of the
            day within the local timezone;
            var cDate = "1-Jan-1970 " + cTime; // add date to time string - needed for conversion;
            // convert to date object;
            var oDate = util.scand("dd-mmm-yyyy " + cFormat, cDate);
            // get number of milliseconds from Epoch date at UTC meridian;
            var nDate = oDate.getTime();
            // convert value to mintues from Epoch date at UTC and remove the timezone offset in minutes;
            // ( 1000 milliseconds in second, 60 seconds in minute);
            var nMin = Math.floor(nDate / (1000 * 60));
            //remove the timezone offest in minutes from the value;
            nMin -= oDate.getTimezoneOffset();
            // return the number of minutes from the start of the day at the local timezone;
            return nMin;


            function Num2hMM(nMin) {
            // convert number of minutes to hours and minutes formatted  (-)h:MM;
            return (nMin < 0? "-" : "") + util.printf("%,2 01.0f", parseInt(nMin / 60)) + ":" + util.printf("%,202.0f", (Math.abs(nMin) % 60));


            • 3. Re: Acrobat 9 STANDARD - Calculate Start/End Time
              KT_2014 Level 1

              Thanks, but I can't seem to open the sample Time Sheet. Also, the closest thing I could find to an "open page action" was "Document Will Close" under Document Actions. Maybe I'm not cut out for this script/function stuff!