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

How to calculate time difference between 2 time fields

Participant ,
May 15, 2017 May 15, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
7.3K
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 ,
May 16, 2017 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 Photoshoptographe
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
Participant ,
May 16, 2017 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.

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
LEGEND ,
May 17, 2017 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.

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
Participant ,
May 17, 2017 May 17, 2017

I found task that is very similar to my:

http://forum.planetpdf.com/wb/default.asp?action=9&read=64228&fid=5

Just check the last post. The person said he solved the problem. I did like he suggested but my result field still look like decimal number but I would like to get result in format HH:MM. What is skipped in that example?

Thanks.

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 ,
May 16, 2017 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 Photoshoptographe
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
Participant ,
May 16, 2017 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

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 ,
May 17, 2017 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 Photoshoptographe
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 ,
May 16, 2017 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

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
LEGEND ,
May 17, 2017 May 17, 2017

It does not handle the DST fall time adjustment.

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 Beginner ,
May 17, 2017 May 17, 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.

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
LEGEND ,
May 18, 2017 May 18, 2017
LATEST

DateTimeCalculation2  has the time calculations using the JavaScript Date object and splitting the HH:MM approaches. If one includes the date times that include the change from Day Light Savings Time or Summer Time the number of hours will be different than just using the hours and minutes. In the spring adjustment one hour is lost and in the fall adjustment 1 hour is added. These changes reflect the change in the time zone offset for the user's local. It should be noted that the user's computer time zone setting controls how JavaScript will or will not make these adjustments.

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