Skip to main content
Participant
November 14, 2016
Answered

Time calculations in adobe acrobat pro dc.

  • November 14, 2016
  • 9 replies
  • 13526 views

I am have the hardest time figuring this out.  Two whole days.  I am trying to configure time and setting it in regular time. 

So what I need is as follows

Date                      Time in               time out       Total Time

September 1          8:00am                2:30pm         6:30 and or 6.5

But every time I put in any calculations it does not come out correct.

Please help

I can actually send you the PDF to make this seem easier.

This topic has been closed for replies.
Correct answer gkaiseril

I believe the issue is about computing the elapsed time or the time worked.

The OP's use of the simplified field notation does not work because there are non-numeric characters in the values being processed. In order for values to be processed in the Simplified Field Notation they must consist of an option sign ( + or -) numeric digits and optional decimal point and more digits. The presence of the ":" makes the value a string and dropped from the calculation. Only Custom JavaScript code can process this type of data.

The approach for the coding is converting the time into the JavaScript date object, This object contains or can compute various information about the date. It also has assigns a unique value to every millisecond. This number can be used to compute the difference between to date time combinations or compute a future date time combination.

There is a limited second way to computer time differences by parsing the time strings into hours and minutes and then doing the needed math. This method is very limited and cannot be used if the time interval includes the period of time when Day Light Savings Time change occurs or one is computing the time difference involving 2 different time zones.

See Thom Parker's Working with date and time in Acrobat JavaScript (Part 1 of 3), Working with date and time in Acrobat JavaScript (part 2 of 3) , Working with date and time in Acrobat JavaScript (part 3 of 3)

Adobe Acrobat JavaScript API Reference util.scand

Mozilla Development Network JavaScript Reference Date object

9 replies

Participant
November 13, 2020

How would I make a calculation if i need the regular hours and overtime hours and total hours but i don't have time in and time out for each day, i only have the total number of hours per day.

Participant
November 13, 2020

try67
Community Expert
Community Expert
November 13, 2020

What's the formula for regular time v. overtime, then?

Participant
June 15, 2018

I figured it out!  just copy the "custom format script" over and it fixed the issue. Thank you for providing the example form.

Inspiring
November 16, 2016

See  Date Time Calculation for a working example of your problem. Be sure to try the date Summer Time, Day Light Savings Time, or War Time begins and use the hours of around 2:00 am.

Participant
June 15, 2018

Good Evening gkaiseril,

If I have multiple "Total Time Worked" field how can I tally and them together? Also, how do I keep the same formatting?

Thank you

Legend
November 15, 2016

Sorry no I can't do private consultations. But if you can share it publicly someone may have time to take a look.

gkaiserilCorrect answer
Inspiring
November 15, 2016

I believe the issue is about computing the elapsed time or the time worked.

The OP's use of the simplified field notation does not work because there are non-numeric characters in the values being processed. In order for values to be processed in the Simplified Field Notation they must consist of an option sign ( + or -) numeric digits and optional decimal point and more digits. The presence of the ":" makes the value a string and dropped from the calculation. Only Custom JavaScript code can process this type of data.

The approach for the coding is converting the time into the JavaScript date object, This object contains or can compute various information about the date. It also has assigns a unique value to every millisecond. This number can be used to compute the difference between to date time combinations or compute a future date time combination.

There is a limited second way to computer time differences by parsing the time strings into hours and minutes and then doing the needed math. This method is very limited and cannot be used if the time interval includes the period of time when Day Light Savings Time change occurs or one is computing the time difference involving 2 different time zones.

See Thom Parker's Working with date and time in Acrobat JavaScript (Part 1 of 3), Working with date and time in Acrobat JavaScript (part 2 of 3) , Working with date and time in Acrobat JavaScript (part 3 of 3)

Adobe Acrobat JavaScript API Reference util.scand

Mozilla Development Network JavaScript Reference Date object

Participant
November 30, 2020

Hello, I am getting negative numbers with this calculation.

I.e. start 22:45 End 03:15 result is -20:30 instead 04:30 I am trying to do flight time calculation departure time is 22:45 arrival time 03:15 next day, I need total hours flown

 

var hrsStart = parseInt(this.getField("time2_1").value.split(":")[0]); var minStart = parseInt(this.getField("time2_1").value.split(":")[1]); var hrsEnd = parseInt(this.getField("time4_1").value.split(":")[0]); var minEnd = parseInt(this.getField("time4_1").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; } this.getField("flight1").value = hrsRez + ":" + minRez; if(flight1 < 0) {// Shift 24 hours flight1 += 24; }

try67
Community Expert
Community Expert
November 30, 2020

The last line of the code does nothing, and is also not set up correctly.

JR Boulay
Community Expert
Community Expert
November 15, 2016

Creating a listbox is well explained in Acrobat's Help.

For a JavaScript drop down you can start here (clic the "Ressources" links): create drop down menu (PDF Forms)

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
November 15, 2016

I expect my employees to type in 8:00 am(start time) and 5:00 pm (end time)

It is easier to get a correct preformatted input via a listbox or a JavaScript drop down menu.

Acrobate du PDF, InDesigner et Photoshopographe
Participant
November 15, 2016

I have no clue of how to create that.  Would you mind helping?

Inspiring
November 14, 2016

Do you ever expect the time entries to include 1:00am to 3:00am?

If so on certain date you will need to adjust for time changes brought about by Day Light Savings Time.

Will the elapsed time value ever be negative?

What results are you getting?

Have you looked at the Acrobat JavaScript API Reference, the Mozilla JavaScript Reference, and Thom Parkers series on date and time calculations at Acrobat Users?

This calculation can only be done using Custom JavaScirpting.

Legend
November 14, 2016

Please let us know script you currently have to calculate, and then we can hopefully help you understand how to fix it. Also please give the formats of the input and output fields, and where you set the script. Also, what do you expect your users to ACTUALLY TYPE in the field?

Participant
November 14, 2016

I am subtracting both times (Feild13-Feild1)

The formats are HH:MM:tt

I expect my employees to type in 8:00 am(start time) and 5:00 pm (end time)

thank you for the help!