• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit Search
0

JavaScript Form Field Time Calculation

Community Beginner ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

I am trying to calculate the difference between 2 form time fields in a 3rd field. I have set the formats for all 3 to none and the time fields are in the format 12:00. The script I entered for the 3rd result field is:

_____________________________________________________________________

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

var cStop = this.getField("OUT").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 = "";

______________________________________________________________

I am not getting any result and the field remains blank. I would appreciate any suggeastions.

Thanks!

TOPICS
JavaScript , PDF forms

Views

253

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 ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

There is no function called parseTime() in Acrobat's JavaScript. You should have gotten an error message on the JavaScript console. If you need to distinguish between AM and PM, it gets a bit more involved (for 24h format, you can just split on the ":" and process the two elements into minutes since midnight). I would create a fake data/time string, using e.e. 1/1/2023 as the date and the actual time. Then you can use the util.scand() function to parse that string and convert to a date object. 

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 ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

LATEST

This question has already been answered dozens of times.

Please start here:

https://community.adobe.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

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