Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

How to calculate worked hours from time fields?

Avatar

Level 1

Hi, Im a reeeaall new one in livecycle, and i need to calculate hours worked from 4 time fields (morning in - morning out | afternoon in - afternoon out)  in a numeric field, for example: 2.75 hours

Please help me, I have my form ready for the script, if some body can give me (and explain please ) some xml & javascript code... repeat... Im a real newbee...

1 Reply

Avatar

Former Community Member

In Javascript the Date object can also deal with time. To do date or time arithmetic you need to convert

the input values into a standard time (valueOf returns the number of milliseconds between midnight Jan1, 1970 and the Date and time set in the object). If all input are set this way then subtracting the two times that you want would yield you a result in millioseconds then you can convert that to the appropriate units that you want.

If you are new to Javascript then this might be a bit much.....but it is the most reliable way to do it as far as I know.

It woudl be easier in FormCalc but the principal is the same.

Paul