# Time Calculation in PDF Form - 1h too much?

New Here ,
Jan 27, 2021 Jan 27, 2021

Copied

Hey guys!

I am currently trying to build a PDF form with some time calculating. I am a total beginner and copied some code I found online and tried some own stuff. And it almost works!

The problem is only, when the Minutes at the Start time are larger than at the End time, there is one hour too much?! You can see in the attached Screenshot what I mean. Instead of "01:50" it should be "00:50" of course...

I don't know why because I can't see where I should correct the code? Do you know what I can do?

Thanks!

``````var hrsStart = parseInt(this.getField("ALBeginn").value.split(":")[0]);
var minStart = parseInt(this.getField("ALBeginn").value.split(":")[1]);
var hrsEnd = parseInt(this.getField("ALEnde").value.split(":")[0]);
var minEnd = parseInt(this.getField("ALEnde").value.split(":")[1]);
if (minStart > minEnd) {
var minRez = 60 + minEnd - minStart;
var hrsRez = hrsEnd - 1 - hrsStart;
} else {
var minRez = minEnd - minStart;
}   var hrsRez = hrsEnd - hrsStart;

if (hrsRez<0) {hrsRez = hrsRez + 24}
if (hrsRez < 10) { hrsRez = "0" + hrsRez }
if (minRez < 10) { minRez = "0" + minRez }
this.getField("ALGesamt").value = hrsRez + ":" + minRez;``````

TOPICS
Create PDFs, Edit and convert PDFs, How to, JavaScript, PDF forms

Views

49

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

New Here , Jan 27, 2021 Jan 27, 2021
SOLVED! The } slipped a line 

Likes

New Here ,
Jan 27, 2021 Jan 27, 2021

Copied

LATEST

SOLVED!

The } slipped a line 🙂

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources