3 Replies Latest reply on Mar 8, 2015 6:01 PM by livsantos

    Calculate Hours Between Clock-in and Clock-out Times?


      Hi all!


      This is my first post to the Adobe community.  I'm here because I need your expertise.  I have no experience in coding (Javascript), but am hoping to copy code and use it for personal and business purposes.

      I have timesheets in .pdf format.  The text fields are fillable.  I have columns for "time-in/clock-in"..."time-out/clock-out"...and "total hours"  I want the user to input the "time-in" and "time-out" in 24-hour (military time), and have it automatically converted to 12-hour (AM-PM) time.  The "total hours" column would be the difference between "time-out" and "time-in"  and would be in "X hours"


      I have found a .pdf that basically has what I'm looking for.  Please see attachment.  The problem is: it utilizes Livecycle Designer.  And I have no idea how to use this.


      Is there any way this code can be used in Acrobat alone?



      Thank you guys for any help!  I appreciate it greatly!




        • 1. Re: Calculate Hours Between Clock-in and Clock-out Times?
          livsantos Level 1

          Or this timesheet...but have user input times as 24-hour format, and automatically converted to 12-hour format.


          https://forums.adobe.com/servlet/JiveServlet/download/2018579-9887/time%20card%20rev11%20S cripts.pdf

          • 2. Re: Calculate Hours Between Clock-in and Clock-out Times?
            gkaiseril MVP & Adobe Community Professional

            Acrobat does not implement 24 military time so unless you are going to write the needed code for keystrokes, validation, and formatting, I would look at using the civilian 24 hour time format. Also there is 24:00 since that is really 00:00 the next day.


            One needs to convert the inputted time string into the JavaScript date object and then can use the various methods of the date object to extract the data about the time. Since one is computing differences it makes no difference if one counts the milliseconds form midnight of the starting day or the Epoch date since the bias for the starting date will be removed by computing the difference.


            I would start out with computing the time for one in and out cycle, then see what the common repeated code is and develop a reusable function for those blocks of code. That will make the in and out cycle computation use less code and if an error is found in the common code there is only one place to correct it.


            A sample script to get you started:


            var cTimeIn = "9:00 am";
            var cTimeOut = "5:01 pm";
            var cTimeFormat = "h:MMtt";
            var cDateString = "1-Jan-2000";
            var cDateFormat = "d-mmm-yyyy";
            // convert time strings to date object;
            var oTimeIn = util.scand(cDateFormat + " " + cTimeFormat, cDateString + " " + cTimeIn);
            var oTimeOut = util.scand(cDateFormat + " " + cTimeFormat, cDateString + " " + cTimeOut);
            // compute difference in millisconds;
            var nDiff = oTimeOut.getTime()  - oTimeIn.getTime();
            // convert milliseconds into hours;
            var nHours = nDiff / (1000 * 60 * 60);
            app.alert("Hours worked: " + nHours, 3, 0);



            You should become familiar with the MDS JavaScript reference and Acrobat's JavaScript API Reference. Both are freely available.

            • 3. Re: Calculate Hours Between Clock-in and Clock-out Times?
              livsantos Level 1

              Thanks for the reply, !


              It seems like the 24-hour military time is a pain.  I've been trying a different approach.



              I was able to modify the Javascript code to my liking.  User is able to input clock-in time and clock-out time.  The difference is automatically computed in the "Lunch" column.  Here is my problem.  I would like to manually enter the hours in the "TOTAL HOURS" column.  Then, the remainder or difference to be the lunch hours.  For example, Clock-In time is 07:00am...Clock-Out time is 10:00 pm.  The difference is 15 hours.  But I would like to manually enter "10.00" hours in the "TOTAL HOURS" column...and have "5.00" hours automatically computed in the "LUNCH" column.


              Is this something that can reasonable coded in Acrobat?  Or would I need to resort to another program?


              Here's the .pdf file that I have been working on.  I've been trying different ideas to get this to work.  None have worked so far.

              http://s000.tinyupload.com/download.php?file_id=79368608079468627047&t=7936860807946862704 744192