Skip to main content
Known Participant
March 22, 2017
Question

Working with time fields

  • March 22, 2017
  • 1 reply
  • 343 views

Sorry, I am a beginner but cannot find the exact answer in the previous questions.

I have an adobe form with a text field (formatted to time HH:MM) in which the user enters a time in the format HH:MM. There is another text field, this one returns a numerical calculated value (which varies dependent on other inputs). I need the form to be able to add the value of the second field to the inputted time and return the answer in a third text field as a time in HH:MM. Please help

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
March 22, 2017

This code should do the trick:

event.value = "";

var startTime = this.getField("StartTime").valueAsString;

if (startTime!="") {

    var d = util.scand("mm/dd/yyyy HH:MM", "01/01/2017 " + startTime);

    var v = this.getField("AddTime").valueAsString;

    if (v!="") {

        var addTimeHours = Number(v);

        var msPerHour = 3600000;

        d.setTime(d.getTime() + (addTimeHours * msPerHour));

        event.value = util.printd("HH:MM", d);

    }

}

Known Participant
March 27, 2017

Thanks try67 that seems to work just fine