Skip to main content
Participant
October 9, 2025
Answered

PDF-Formular Berechnung von Arbeitszeiten

  • October 9, 2025
  • 1 reply
  • 166 views

Hallo Zusammen,

ich erstelle gerade einen Arbeitszeitbericht als Formular. Das Formular soll, wenn die Mitarbeiter auf der Baustelle sind, mobil ausgefüllt werden.

Ich habe zwei Felder (Arbeitszeit von / Arbeitszeit bis) diese sind mit der Formatkategorie Zeit vorgesehen.

In einem dritten Feld (Arbeitszeit) soll nun die automatische Berechnung mit Angabe in Stunden erfolgen.

Kann mir jemand einen Lösungsansatz aufzeigen?

Ich danke euch recht herzlich für die Tipps.

MK

Correct answer Thom Parker

There are several different ways to perform time calculations. The simplest is to parse the time format, subtract the parts, and then reformat.  This method depends on the hours always being in the same day. If the hours cross midnight, then a modification is needed. If the times cover several days, then a more complicated technique is required. 

 

So here's the simple bit, I just made up form field names. You'll need to modify this script to match the fields on your form. 

 

Place this code into the calculation script for the  "Working Hours" field

 

// Set Default
event.value = "";

var rgTimeParse = /^\s*(\d{1,2})\:(\d{2})\s*$/;
var strStart = this.getField("StartTime").valueAsString;
var strEnd = this.getField("EndTime").valueAsString;
if(rgTimeParse.test(strStart)){
   var nStart = Number(RegExp.$1) + Number(RegExp.$2)/60;
   if(rgTimeParse.test(strEnd)){
      var nEnd = Number(RegExp.$1) + Number(RegExp.$2)/60;
      var nTimeTotal = nEnd - nStart;
      var nHours = Math.floor(nTimeTotal);
      event.value = util.printf("%02d:%02d",nHours , (nTimeTotal-nHours)*60);
   }
}

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
October 9, 2025

There are several different ways to perform time calculations. The simplest is to parse the time format, subtract the parts, and then reformat.  This method depends on the hours always being in the same day. If the hours cross midnight, then a modification is needed. If the times cover several days, then a more complicated technique is required. 

 

So here's the simple bit, I just made up form field names. You'll need to modify this script to match the fields on your form. 

 

Place this code into the calculation script for the  "Working Hours" field

 

// Set Default
event.value = "";

var rgTimeParse = /^\s*(\d{1,2})\:(\d{2})\s*$/;
var strStart = this.getField("StartTime").valueAsString;
var strEnd = this.getField("EndTime").valueAsString;
if(rgTimeParse.test(strStart)){
   var nStart = Number(RegExp.$1) + Number(RegExp.$2)/60;
   if(rgTimeParse.test(strEnd)){
      var nEnd = Number(RegExp.$1) + Number(RegExp.$2)/60;
      var nTimeTotal = nEnd - nStart;
      var nHours = Math.floor(nTimeTotal);
      event.value = util.printf("%02d:%02d",nHours , (nTimeTotal-nHours)*60);
   }
}

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often