Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Javascript that calculates the difference between two times

Maria_Loreto_Nu
Level 2
Level 2

Hi all..

I can't calculate the difference between two times fields.

For example: I have 3 dateTime fiels but in the Date Format I need only the time (hour)

How can I calculate the difference between 2 times?

time 1:  15:45:00

time2:   16:30:00

The result is: ....00:45:00

Thanks a Lot

María

3 Replies
radzmar
Level 10
Level 10

Hi,

this can be done easy with FormCalc.

Put this script into the calculate:Event of the field which should display the difference.

emmad11800879
Level 2
Level 2

I have tried to get this code to work but without any luck - I am not sure what I am doing wrong - I have ensured the two fields are called tstart and tend and am using formcalc and calculate - I tried adjusting the code slightly but still without any luck.

Please can you help?

I am trying achieve how much time between a start time and end time (ideally a code that works overnight) - I am using Livecycle ES2

var tStart = Time2Num(tstart.formattedValue, "HH:MM:SS")

var tEnd = Time2Num(tend.formattedValue, "HH:MM:SS")

if (tStart ne 0 and tEnd ne 0) then

     //if start time is lower than end time.

     if (tStart < tEnd) then

          Num2Time(Abs(tStart - tEnd) - 7200000 + 1000, "HH:MM:SS")

     //If start time is higher than end time    

     else

          Num2Time(Abs(86400000 - Abs(tStart - tEnd) - 7200000 + 1000), "HH:MM:SS")

     endif

endif