subtract one time field from another to get duration

New Here ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Seems simple? why does nothing show up in my duration feld, also set as HH:MM?  I tried the simple script in computation for subtraction of one field from another. Nothing shows up. 

TOPICS
PDF forms

Views

36

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Dates and times are complicated.  There is no built-in functionality in Acrobat Forms for handling date/time with simple math and unfortunately there is nothing in the JS library for reducing data/time calcs to simple math either.   To do this you just gotta write the code.

First, the date/time values in the form fields are not actual data/times, they are text representing a date/time.  To perform a caculation they have to be converted to a Date Object. But, a time does not exist by itself. A time value is always on a day, so you have to provide a date and time together to create a date object. Then you can get the difference in miliseconds between the two dates, which you will then need to convert to text representation of the difference. 

 

Here's are some articles on the topic.

 

https://acrobatusers.com/tutorials/date_time_part1/

https://acrobatusers.com/tutorials/date_time_part2/ 

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

   

 

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

Likes

Translate

Translate

Report

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
New Here ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Too bad- it took me a few seconds to make such a set of fields in File
Maker. I mistakenly thought they had similar functionality!
Jill

(PII removed by moderator)

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

LATEST

This issue was discussed here many times in the past, and complete code examples were given for it. And no, it's not a trivial thing to do. I recommend you try searching for similar topics first. If you can't find any, post again.

Likes

Translate

Translate

Report

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