These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Elapsed Time Formula

MetroTraveler
Registered: Feb 13 2011
Posts: 6
Answered

I am trying to create a PDF in Acrobat Pro to calculate Time Elapsed in an Hours:Minutes format. For example 1:00 - 2:30 = 1:30. I have three fields: "Start Time", "End Time", "Total Time". I want the calculation to go into the "Total Time" field.
 
I have no programming experience and really have no idea what i am doing. Any help will be greatly appreciated. I can email the form to anyone willing to help. Thanks.

My Product Information:
Acrobat Pro 9.4, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Here's the custom calculation code that you can use for the Total Time field to do this calculation:

sTime = this.getField("Start Time").value;
eTime = this.getField("End Time").value;

if (sTime!="" && eTime!="") {
sTimeHours = sTime.split(":")[0];
sTimeMinutes = sTime.split(":")[1];
eTimeHours = eTime.split(":")[0];
eTimeMinutes = eTime.split(":")[1];
tTimeHours = eTimeHours - sTimeHours;
tTimeMinutes = eTimeMinutes - sTimeMinutes;
if (tTimeMinutes<0) {
tTimeHours--;
tTimeMinutes = 60 + tTimeMinutes;
}
tTime = tTimeHours + ":" + tTimeMinutes;
event.value = tTime;
} else event.value = "";

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

MetroTraveler
Registered: Feb 13 2011
Posts: 6
Works perfectly! Thank you... Saved me a lot of headaches.