Skip to main content
Participating Frequently
July 7, 2023
Answered

Adding Integer to a Time and print the calculated Time to a Field

  • July 7, 2023
  • 1 reply
  • 1618 views

Hi all,

 

I am creating a PDF-Form as a Service Sheet. But now iam stuck in a Middel of thing.

i have following Fields: A, B , C

Field A (Start Time) is a Time Field in Format HH:MM

Field B (End Time) is a Time Field in Format HH:MM

Field C is a Variabel Integer Field (Text Field)

 

I would like to Program this in Javascript to do the Follwing:

When i enter a Time in Field A in Format HH:MM and a Number in Field C. The Output in Field B will be the Sum of Time in Field A und The Number from Field C in HH:MM format.

 

Exampel:

Field A have the Value 14:00.

Field C have the Value 2

Field B should give the Value 16:00

 

I tried some Javascripting but without success

Iam using Adobe Acrobat Pro 17.

I would be very Thankfull for your help.

 

 

 

This topic has been closed for replies.
Correct answer Nesa Nurani

Use this in field B as custom calculation script:

var a = this.getField("A").valueAsString;
var c = Number(this.getField("C").valueAsString);

if(a !== ""){
var cTime = util.scand("dd/mm/yyyy HH:MM", "01/01/2000" +a);
cTime.setHours(cTime.getHours() +c);
event.value = util.printd("HH:MM", cTime);} 
else
event.value = "";

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
July 7, 2023

Use this in field B as custom calculation script:

var a = this.getField("A").valueAsString;
var c = Number(this.getField("C").valueAsString);

if(a !== ""){
var cTime = util.scand("dd/mm/yyyy HH:MM", "01/01/2000" +a);
cTime.setHours(cTime.getHours() +c);
event.value = util.printd("HH:MM", cTime);} 
else
event.value = "";
Participating Frequently
July 7, 2023

Works Like Magic. Many many Thanks.