3 Replies Latest reply on Mar 1, 2008 11:15 PM by (Irfan_Asrar)

# Calculating Difference between "StartTime" and "EndTime" & Displaying it in Third Field

I have looked and looked for a solution to this problem and all I find is reference to "Date Arithmetic", none of which seems to work. But I'm a newbie afterall. Here's the problem:

I have three fields, StartTime, EndTime, TtlHours, the latter being read-only. Data is entered into the first two in the form of "h:MM tt". The third field uses javascript to solve for the difference and convert the difference into decimal hours.

Is this possible?

Thanks for any help in advance,
Steve
• ###### 1. Re: Calculating Difference between "StartTime" and "EndTime" & Displaying it in Third Field
If you are using AcroForms JavaScript, you need to have the date and time string to do the math and the time interval is milliseconds. LiveCycle Designer can use just the time if the interval is all within 1 day and the time interval is seconds.

See Help Needed Formula, http://forum.planetpdf.com/wb/default.asp?action=9&read=52819&fid=100#144644 , for an example.

• ###### 2. Re: Calculating Difference between "StartTime" and "EndTime" & Displaying it in Third Field
Thanks for the quick response. Your info clarified a lot for me. I was able to quickly create the following code for the third field formatted as a decimal number:

var oStart = util.scand("mm/dd/yy hh:mm", util.printd("mm/dd/yy ", new Date()) + this.getField("Start.0").value);

var oEnd = util.scand("mm/dd/yy hh:mm", util.printd("mm/dd/yy ", new Date()) + this.getField("End.0").value);

var DiffHours = (oEnd.valueOf() - oStart.valueOf()) / 1000 / 60 / 60;

this.getField("Hours.0").value = Number(DiffHours);

Couldn't have done it without you!

Steve
• ###### 3. Re: Calculating Difference between "StartTime" and "EndTime" & Displaying it in Third Field
Geo,
Would you happen to have an example of the oppsite, say I wanted to calculate the total hours worked, example two field, one has hours worked HH:MM (Field1) the second has HH:MM (Field2).. How would I go about adding them to give me the total hours worked. I tried to use the example about but found that it only works if your trying to find the difference but not a total.....

Irfan