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

calculate time

fvaz
Registered: Aug 25 2010
Posts: 3

hello there,
 
i whant to know if the acrobat pro can calculate time in the forms.
for ex: 01:30 + 01:30 = 03h 00 min.
 
Does it calculate that ??
How ?

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Yes it can be done.

All date and time values in Acrobat and LiveCycle Designer are specially formatted character stings that need to be converted to numeric values prior to any mathematical operation.

The following code can be run in the JavaScript console or a button.
function sHHMM2Num(sTime) {// convert time string formatted as HH:MM to minutes // split value at ':' into and array of hours and minutesvar aTime = sTime.split(":");// convert hours element (hours from string) to minutesvar nMinutes = 60 * aTime[0] ; // add the minutes element (minutes from string) to nMinutesnMinutes = nMinutes + Number(aTime[1]); // return minutesreturn nMinutes;}  // get the start string from a variable, field value, or other sourcevar cStart = "01:30";// convert start time string to number of minutesvar nStart = sHHMM2Num(cStart); // get the interval string from a variable, field value, or other sourcevar cInterval = "01:30";// convert interval time string to number of minutesvar nInterval = sHHMM2Num(cInterval); // add the start time in minutes and the interval time in minutesvar nElapsed = nStart + nInterval;  // convert time in minutes to hoursvar nHours = nElapsed / 60;// truncate hours to whole hours onlynHours = Math.floor(nHours); // get the remainder of minutes from time divided by 60var nMinutes = nElapsed % 60; console.show();// display the resultsconsole.println(nHours + " hours and " + nMinutes + " minutes"); // some debugging informationconsole.println("cStart: " + cStart + " is " + nStart + " minutes");console.println("cInterval: " + cInterval + " is " + nInterval + " minutes");console.println("Elapsed time: " + nElapsed + " minutes");

George Kaiser

fvaz
Registered: Aug 25 2010
Posts: 3
hello gkaiseril,

thanks for your answer, but i still have a problem, dont know where to copy the javasript and where to paste it ?? For ex: i created 4 boxes, all of them formated category for time, the last one is the one that calculate the total time. I paste your javascrip in all boxes in the calculate, custom calculation field. Now, i dont know where is my mistake, doesnt work ??

hope to here from you soon,

Thanks
fvaz
Registered: Aug 25 2010
Posts: 3
Still have difficulty in how to do the javascript to calculate time. My major problem is that i dont know where to past the codes.
can anyone help me.
thanks in advance
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can use the caluclate event for the result field.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398

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