Skip to main content
Known Participant
May 15, 2017
Question

How to calculate time difference between 2 time fields

  • May 15, 2017
  • 3 replies
  • 7815 views

I have a form with a StartTime and EndTime field formatted like HH:MM , and a TotalHours field formatted like (Number, 2 decimal places, separator style 1234.56). In that field I would like to display result of time calculation.

I'm expecting to get such result:

StartTimeEndTimeTotal Hours
9:1510:301:15
8:3011:152:45
10:0511:301:25

Please help with JavaScript code. Thanks.

This topic has been closed for replies.

3 replies

try67
Braniac
May 16, 2017

If you don't want to mess around with writing code, even using Joel's handy library, consider this tool I've developed which allows you to set up such calculations easily and quickly: Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

Inspiring
May 17, 2017

It does not handle the DST fall time adjustment.

eugenez79468640
Participating Frequently
May 18, 2017

DST is Daylight Saving Time. Is it correct? Is it possible to solve my problem? If yes can somebody help to show sample javascript for that task and briefly explain the code?

Thanks.

JR Boulay
Braniac
May 16, 2017

You should read at least the second paragraph:

What it does

The Date Library for Adobe Acrobat adds methods to the native JavaScript Date Object that make it easier to:

- Add days, months, years, or any other time increment to a Date object in a single call… you just pass in a JSON object with the parameters you need.

- Calculate a person’s age either by using a Date Object or a string representing a date.

- Calculate the next business day.

- Calculate the first business day of the next month.

- Use named patterns when formatting date object.

- Detect leap years.

Acrobate du PDF, InDesigner et Photoshopographe
eugzlAuthor
Known Participant
May 16, 2017

I did those steps:

To install the Date Library installer.

  1. Download the Custom Command file.
  2. Choose Tools > Action Wizard.
  3. Select Manage Custom Commands from the toolbar.
  4. In the Manage Custom Commands dialog box, choose Import and select the .XML file you just downloaded.
  5. Once you are done, click Close.

What do I need to do to solve my problem?

Thanks

JR Boulay
Braniac
May 17, 2017
What do I need to do to solve my problem?

As far as I can see, you should learn to read the descriptions and instructions until the end.

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Braniac
May 16, 2017

You don't need to reinvent the wheel, PracticalPDF made it for you: http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/

Acrobate du PDF, InDesigner et Photoshopographe
eugzlAuthor
Known Participant
May 16, 2017

Hi JR_Boulay. Thanks for replay.

I just newer in javascript. If I understand correct link just explain how to print formatted date. I need to get calculation result in correct time value. How to do that?

Thanks.

Inspiring
May 17, 2017

I have found that calculating time intervals without the date can lead to issues when this is done in areas the observe Day Light Savings Time. This issue arises if the included time interval include the date and time at which the local time is adjusted. So you might need to take this into account with your form design.