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

calculate total hours between two date fields and two time fields

Participant ,
May 12, 2017 May 12, 2017

Hi All.

In my PDF form I would like to calculate total hours between two date fields StartDate and EndDate which formatted like m/d/yyyy. And two time fields StartTime and EndTime which formatted like HH:MM. If StartDate and EndDate are the same so total hours between = 0. If startDate and EndDate are different (5/10/2017 and 5/11/2017) so Total = 7.

For instance:

StartDateEndDateStartTime
EndTimeTotal
5/10/20175/10/201709:0013:004:00
5/10/20175/11/201709:0015:3012:30

How to solve that problem?

Thanks.

TOPICS
Acrobat SDK and JavaScript , Windows
890
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 12, 2017 May 12, 2017

I have a free Date library for ACrobat that has a "daysBetween" method that will make that calculation easier.

Link to the library

http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/ 

Link to daysBetween

Date - Extended Date Object for Adobe Acrobat

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 12, 2017 May 12, 2017

Doesn't it only do date calculations, not time ones?

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 12, 2017 May 12, 2017

It has elapsed time as well. From there you can get hours.

Date - Extended Date Object for Adobe Acrobat

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 12, 2017 May 12, 2017

Neat!

On Fri, May 12, 2017 at 11:19 PM, Joel_Geraci <forums_noreply@adobe.com>

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 12, 2017 May 12, 2017

I found code and modified it for my task

var cEnd = this.getField("EndDate").value

var cStart = this.getField("StartDate").value;

if(cEnd != "" & cStart != "")

{

     var oEnd = util.scand("m/d/yyyy", cEnd);

     var oStart =util.scand("m/d/yyyy", cStart);

     var nEnd = Math.floor(Number(oEnd) / (1000 * 60 * 60));

     var nStart = Math.floor(Number(oStart) / (1000 * 60 * 60));

     event.value = nEnd - nStart;

}

My problem now how to calculate:

- If StartDate and EndDate are the same so total hours between = 0.

- If startDate and EndDate are different (5/10/2017 and 5/11/2017)  Result = 7.

                                                               (5/10/2017 and 5/12/2017)  Result = 14

and so on.

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

It is not clear how one gets a value of 7 when the start and end dates are the same. Does the start and end time have any affect on the result?

The same applies if the start and end date are different. What happens if the dates are more than 2 days different?

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