Acrobat 7: LiveCycle Designer- Calculating Hours From Two Time Fields

I am designing a form for scheduling employees that has two fields, 'In', and 'Out'. A third field is used to calculate the difference in hours(example: 1.75 hours). I am having trouble getting the calculation to return hours instead of a pure number. When 'In'= 11:30 and 'Out'=12:30, for example, the difference is shown as '100', instead of '1'. Is there a way to accomplish what I need for this form?  Thank you.
Who is Participating?
Karl Heinz KremerCommented:
If you are interested in the number of hours, use something like this:

var difference = IsoTime2Num(Out) - IsoTime2Num(In);
difference / 1000 / 60 / 60;

The IsoTime2Num() function will convert the time (in 24h format) to milliseconds since the "epoch", so the subtraction of out and in times will leave you will milliseconds. The second line converts this value to hours.
Karl Heinz KremerCommented:
What do you get for e.g. in=11:00 and out=12:35 ?

How are you calculating the diffrence?
frizzellAuthor Commented:
The time fields are 'In' and 'Out'. In the 'Hours' field, where I want the hours worked to be calculated, I use  'Out - In', using FormCalc. So, if Out='12:25' and In='11:00', the 'Hours' total shows as 135 instead of 1:35. If Out=5:00pm and In=11:00am, the Hours total shows as 600. The user enters the time in 24-hour format, ex: 1300 = 1pm. Thank you for your time.
frizzellAuthor Commented:
Thank you very much for the answer. It was EXACTLY the functionality that I needed. The speed and accuracy of your solution impressed me.
Very nice code.

The IsoTime2Num() function will convert the time (in 24h format) to milliseconds since the "epoch",
what if i want to convert the time in 12h format?
how will i go about it.

Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.