• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PDF timesheet calculation

New Here ,
Feb 28, 2020 Feb 28, 2020

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?

 

 

TOPICS
Acrobat SDK and JavaScript

Views

10.3K

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

Community Expert , Feb 28, 2020 Feb 28, 2020

Change the last line to:

event.value = Number(event.value) + Number(output);

Votes

Translate

Translate
Community Expert ,
Apr 01, 2020 Apr 01, 2020

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. 

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

Votes

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
Community Beginner ,
Apr 01, 2020 Apr 01, 2020

Copy link to clipboard

Copied

Sir,

I don't know if I should use military time or regular time . I'm a little rusty on calculations.

Here's what I have;
8 12 1 5 = 8 hrs
12-8 = 4 4*60 = 240 min 240+240 = 480/60 = 8 hrs
5-1= 4 4*60 = 240 min

Now for the half hours
8:00 12:00 13:30 17:00 = 7.5 hrs
12:00-8:00 = 4 hrs
17:00 - 13:30 = 3.5 hrs
17.00*60 = 1020
13.3*60 = 798
1020 - 798 = 222 222/60 = 3.7 hrs

Now for the quarter hours
7:15 12 1 5
12:00 - 7:15 = 4:15
12*60 = 720
7.15*60=429
720-429=291 291+240 = 531 531/60=8.85 hrs ???

8:45 12 1 5
12*60 = 720
8.45*60 = 507
720-507=213 213/60 = 3.55 hrs ??

Sincerely,
Cathy

Votes

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
Community Expert ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

You should debug your code.
You can display the internal values:

 

console.show();
console.println("hourDiff: " + hourDiff + " minDiff: " + minDiff);

Votes

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
Community Beginner ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Bernd,

Thank you!

I’m working on that and reviewing basic javascript. 😊

Sincerely,
Cathy Walton-Woodson, M.A.
DVC Counseling Office Supervisor
925-969-2148
cwoodson@dvc.edu

Votes

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
Community Expert ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

You must correct the script before you simplify it.

Votes

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
New Here ,
Apr 03, 2020 Apr 03, 2020

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...

Votes

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
Community Beginner ,
Sep 23, 2022 Sep 23, 2022

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.

Votes

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
Community Expert ,
Sep 25, 2022 Sep 25, 2022

Copy link to clipboard

Copied

LATEST

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.

Votes

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