Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
16

Adobe Pro Calculations of drop down menus

New Here ,
Dec 07, 2023 Dec 07, 2023

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.

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF , PDF forms
475
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2023 Dec 07, 2023
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines