Skip to main content
Participant
December 8, 2023
Question

Adobe Pro Calculations of drop down menus

  • December 8, 2023
  • 1 reply
  • 655 views

I am trying to create a PDF time sheet.

I can figure out how to create drop down menus with start times and finish times for shifts.

But I cannot figure out how to calculate the time in a shift - start time to finish time.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
December 8, 2023

This question has been asked many times. And there are several ways to perform this calculation. 

Time values are not regular calculations, because the user does not enter a time value, they enter a string value that represents a time. 

You can read the basics about time and date handling here:

https://www.pdfscripting.com/public/Date-and-Time-Handling.cfm

 

However, since you are using a dropdown for entering the dates, you have a unique opportunity to make life easier for yourself.  You can make the export values of the input dropdowns the actual time values. For example "8:00" is 8 hours after midnight, so make it the value 8.  "14:30" is 12.5 hours after midnight, so make the export value 12.5.

Next, make the Shift Hours field a read only text field. 

Use this custom calculation script:

 

event.value = this.getField("Finish").value - this.getField("Dropdown7").value;

 

There are more issues that have to be handled to create a complete solution, but getting the calculation right is the first bit. 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often