Skip to main content
Participant
March 16, 2021
Answered

Need Help Creating Timesheet in Adobe Acrobat

  • March 16, 2021
  • 3 replies
  • 3360 views

Hi all, 

I am new to using adobe acrobat and am very confused. I want to convert and old timesheet that had been made in excel into a fillible form on adobe acrobat. I am having trouble with the calulations for the total hours (military time). In excel the sheet calculates using the formula under the hours cell is  =MOD(G8-F8,1) where G8 is time out and F8 is time in. How would I do this in adobe so that I get the same result?

All I want is a simple time in, time out, and total hours, and I want to make sure it can calculate if the times go beyond midnight. 

I would appreciate as much info as I can get, thanks!

This topic has been closed for replies.
Correct answer Kiri0101

I actually found the answer in a different post! Thanks to try67, kudos to you!! The only difference is that in my script I had "TimeInRow1" instead of "Time 3.1" and "TimeOutRow1" for "Time 4.1". Hope this is helpful for anyone that needs!!

var start = this.getField("Time 3.1").valueAsString;
var finish = this.getField("Time 4.1").valueAsString;

if (start=="" || finish=="") event.value = "";
else {
	var startArr = start.split(":") ;
	var finishArr = finish.split(":") ;

	var hourDiff = finishArr[0] - startArr[0];
	var minDiff = Math.floor(((finishArr[1] - startArr[1]) / 60)*100);
	if (minDiff<0) {hourDiff--; minDiff += 100;}
	if (hourDiff<0) hourDiff+=24;
	if (minDiff.toString().length == 1) minDiff = '0' + minDiff;
	event.value = hourDiff + "." + minDiff;
}

3 replies

Participant
March 12, 2024

 

To achieve the same calculation functionality in Adobe Acrobat as in Excel for your timesheet, you can use JavaScript to perform the calculations. Here's how you can set it up:

  1. Open your PDF form in Adobe Acrobat.
  2. Go to the "Prepare Form" tool.
  3. Select the "Text Field" tool and create fields for Time In, Time Out, and Total Hours.
  4. Right-click on the Total Hours field and select "Properties."
  5. Go to the "Calculate" tab.
  6. Choose "Custom calculation script" and click on the "Edit" button.
  7. In the JavaScript editor, enter the following code:

 

javascriptCopy code
// Calculate total hours var timeIn = getField("TimeIn").valueAsString; var timeOut = getField("TimeOut").valueAsString; if (timeIn && timeOut) { var timeInArray = timeIn.split(":"); var timeOutArray = timeOut.split(":"); var hoursIn = parseFloat(timeInArray[0]); var minutesIn = parseFloat(timeInArray[1]); var hoursOut = parseFloat(timeOutArray[0]); var minutesOut = parseFloat(timeOutArray[1]); if (hoursOut < hoursIn || (hoursOut == hoursIn && minutesOut < minutesIn)) { hoursOut += 24; } var totalHours = (hoursOut - hoursIn) + (minutesOut - minutesIn) / 60; event.value = totalHours.toFixed(2); // Display total hours with two decimal places } else { event.value = ""; // If either Time In or Time Out is empty, clear Total Hours field }
 
  1. Click "OK" to close the JavaScript editor and then "Close" to exit the field properties dialog.
  2. Repeat steps 4-8 for the Time In and Time Out fields if you want them to display a specific format.

This JavaScript code calculates the total hours based on the Time In and Time Out values, taking into account if the times go beyond midnight. Make sure to adjust field names in the script (e.g., "TimeIn" and "TimeOut") to match the names of your actual form fields.

Once you've set up the script, your PDF form should be able to calculate the total hours automatically as you input Time In and Time Out values.

Kiri0101AuthorCorrect answer
Participant
March 16, 2021

I actually found the answer in a different post! Thanks to try67, kudos to you!! The only difference is that in my script I had "TimeInRow1" instead of "Time 3.1" and "TimeOutRow1" for "Time 4.1". Hope this is helpful for anyone that needs!!

var start = this.getField("Time 3.1").valueAsString;
var finish = this.getField("Time 4.1").valueAsString;

if (start=="" || finish=="") event.value = "";
else {
	var startArr = start.split(":") ;
	var finishArr = finish.split(":") ;

	var hourDiff = finishArr[0] - startArr[0];
	var minDiff = Math.floor(((finishArr[1] - startArr[1]) / 60)*100);
	if (minDiff<0) {hourDiff--; minDiff += 100;}
	if (hourDiff<0) hourDiff+=24;
	if (minDiff.toString().length == 1) minDiff = '0' + minDiff;
	event.value = hourDiff + "." + minDiff;
}
Inspiring
March 16, 2021

Just a tip, not sure what format you need, but for example lets say time diff is 7h and 30min,  the above code will give you 7.50 instead of 7:30.

Participant
June 13, 2022

How to solve this problem? Thanks @Asim123 

Peru Bob
Community Expert
Community Expert
March 16, 2021

I've moved this from the Using the Community forum (which is the forum for issues using the forums) to the Acrobat forum so that proper help can be offered.