Copy link to clipboard
Copied
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.
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi.
Instead of reinventing the wheel you should search "Time sheet" on this forum, there are some nice examples to download around here.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Any help is appreciated.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now