Skip to main content
Participant
September 19, 2017
Answered

Timesheet Hours Worked Will Not Display Correctly

  • September 19, 2017
  • 1 reply
  • 882 views

I'm using Adobe Acrobat Pro DC.

I have four fields [amIN0, amOUT0, pmIN0, and pmOUT0] that will auto-populate the Hours Worked field.

My times are formatted to h:MM tt.

I need the HoursWorked results to display 7 hours and 30 minutes as 7.50 NOT 7.30

And 8 hours and 30 minutes should display as 8.50 NOT 8.70

I'm using a simplified notation (amOUT0-amIN0)+(pmOUT0-pmIN0).

Please help. Thank you.

This topic has been closed for replies.
Correct answer try67

Change the last line of the Regular Hours calculation to:

event.value = Math.min(40, normalHours, totalHours);

1 reply

try67
Community Expert
Community Expert
September 19, 2017

You can't do it like that. Time calculations are much more complex than normal math calculations, and require a custom-made script.

There are good tutorials about this subject here:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3

Alternatively, if you don't want to write the code yourself, I've developed a tool that allows you to easily set up this kind of calculation, including the option to show the result in decimal format (ie, 2.5 for two and a half hours, instead of 2:30): Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

joijoyAuthor
Participant
September 20, 2017

Yes, this all seems very complex as I am new to javascript.

However, I've run into another snag.  Hopefully, it is a small fix. The Regular Hours cannot exceed 40 hours. Regular and Overtime should equal Total Hours Worked. What do I need to change to make this work?

This is the custom script for Regular Hours:

var normalHours = Number(this.getField("NormalHours").value);

var totalHours = Number(this.getField("TotalHours").value);

event.value = Math.min(normalHours, totalHours);

This is the custom script for Overtime Hours:

event.value = +this.getField("TotalHrsWorked").value > 40 ? (+this.getField("TotalHrsWorked").value - 40) : 0;

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 20, 2017

Change the last line of the Regular Hours calculation to:

event.value = Math.min(40, normalHours, totalHours);