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

Calculate difference between two time fields

Explorer ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Hi all,

I would appreciate it so much if you could help me out a little with this.

I have a starttime and endtime fields but I would like the form to auto calculate for me once these two fields have been populated.

Example:

  1. How do I make the form calculate “Duration” for me and the “Total” as well.
  2. How do I make the form let the user to move from column to column automatically? For example, after entering start time (HHMM), the cursor would automatically move to the End time column?

Thank you and Regards,

James

TOPICS
Acrobat SDK and JavaScript , Windows

Views

3.5K

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

correct answers 1 Correct answer

Community Expert , Aug 27, 2018 Aug 27, 2018

Change the field's Format to None and use this code for the calculation (this is for the A row):

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

var cStop = this.getField("Stop1").value;

if (cStart != "" && cStop != "") {

    var tStart = parseTime(cStart);

    var tStop = parseTime(cStop);

    var total = (tStop - tStart)/(1000*60*60);

    var totalHours = Math.floor(total);

    var totalMinutes = (total-totalHours)*60;

    var totalHoursString = (totalHours<10) ? "0"+totalHours : ""+totalHours;

    var tota

...

Votes

Translate

Translate
Community Expert ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Are the times always in the same calendar day?

This issue was discussed many times in the past, and complete code examples have been given to answer it.

You should really try searching the forums for "time calculation", or something to that extent.

You might also find these tutorials useful:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3

And if you want a (paid-for) tool that will set it up for you with a few clicks, check out this one I've developed:

Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

Regarding your second question: Do you mean that after the user entered the four digits it will automatically jump to the next field?

Votes

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
Explorer ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Hi

Votes

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
Community Expert ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Change the field's Format to None and use this code for the calculation (this is for the A row):

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

var cStop = this.getField("Stop1").value;

if (cStart != "" && cStop != "") {

    var tStart = parseTime(cStart);

    var tStop = parseTime(cStop);

    var total = (tStop - tStart)/(1000*60*60);

    var totalHours = Math.floor(total);

    var totalMinutes = (total-totalHours)*60;

    var totalHoursString = (totalHours<10) ? "0"+totalHours : ""+totalHours;

    var totalMinutesString = (totalMinutes<10) ? "0"+totalMinutes : ""+totalMinutes;

    event.value = totalHoursString + totalMinutesString;

}

else {

    event.value = "";

}

Votes

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
Explorer ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Hi

Votes

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
Community Expert ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

No, you can't combine the two things, unless you write your own custom keystroke and format scripts, which is not a simple task.

I don't think it's necessary, really. If the tab order is set correctly then the user just needs to press Tab after entering the value, and it will jump to the next field.

Votes

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
Explorer ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

LATEST

Hi

Votes

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