Copy link to clipboard
Copied
Hi guys!
I am a beginner at this and have searched a lot for anwers but haven´t found any that fits my problem.
I have a PDF form timesheet that uses four time inputs. ex. time1in:07:00, time1out:11:00, time2in:12:00, time2out:16:00. Now I want to sum this up in a total hours field and need help with the script to perform this correctly.
I have found a script that works to sum up the total hours of time1in and time1out but I do not know how to extend the script to also add time2in and time2out to the total sum.
The script I have is:
// start
var start = this.getField("8").value;
var startArr = start.split(":");
// finish
var finish = this.getField("9").value;
var finishArr = finish.split(":");
// difference
var hourDiff = Math.abs(finishArr[0] - startArr[0]);
var minDiff = Math.floor((Math.abs(finishArr[1] - startArr[1]) / 60)*100);
if (minDiff.toString().length == 1)
minDiff = '0' + minDiff;
var output = hourDiff + "." + minDiff;
event.value = output;
Is there someone who might be able to help me on this one?
Change the last line to:
event.value = Number(event.value) + Number(output);
Copy link to clipboard
Copied
It's not about JavaScript or anything to do about programming. It's about how you perform a calculation.
Do this: With pencil and paper, work out the calculation manually. The same way you would do it in a math class. Show all steps.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You should debug your code.
You can display the internal values:
console.show();
console.println("hourDiff: " + hourDiff + " minDiff: " + minDiff);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You must correct the script before you simplify it.
Copy link to clipboard
Copied
I also need someone to help GIVE me the script for this. I have not clue what I am doing. I am helping my supervisor create a time sheet to help all other employees submit their time with a PDF file. I have Time In, Time Out, Lunch Start, Lunch End, Total Hours. HELP...
Copy link to clipboard
Copied
Were you able to figure this out? I need the exact same script that can calculate the total hours worked while deducting for the lunch/break.
Copy link to clipboard
Copied
I've developed a (paid-for) script that will allow you to do just that:
https://www.try67.com/tool/acrobat-calculate-time-differences-in-a-worksheet
It can be easily adjusted to deduct the lunch time from the result, too.