Time Calculation in PDF Form - 1h too much?

New Here ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

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;

 Bildschirmfoto 2021-01-27 um 12.08.42.png

 

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

Views

49

Likes

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

correct answers 1 Correct Answer

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

Likes

Translate

Translate
New Here ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

LATEST

SOLVED!

 

The } slipped a line 🙂

Likes

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