Level 1

0% to

Level 2

Tip /

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

View all

## Simple Time Duration Calculation

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile
shawnFMU
Level 1

11-10-2018

I need a simple Time Duration Calculation. What I've read and piece together, I can't seem to get it to work.

Time2Num and Num2Time...

Help!

In 1 day, Start time and End time equal how much Total time. Example 1:00 to 3:00 equal 2

I've set three Text Fields.

Time1

Time2

Total

Total text field, Calculate event, JavaScript

var start = Time2Num(Time1.formattedValue, "HH:MM")

var end = Time2Num(Time2.formattedValue, "HH:MM")

var dur = Num2Time(end + start, "HH:MM")

this.rawValue = dur;

#### Accepted Solutions (1)

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile
mouslander
Level 4

12-10-2018

Here is a script I used. It was odd that it wasn't working and I realized my form was set as "Static" once I saved it as "Dynamic" it worked.

FormCalc

var a = (Time2Num(Time1.formattedValue)/ (60 * 60 * 1000))

var b = (Time2Num(Time2.formattedValue)/ (60 * 60 * 1000))

\$ = b-a

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile
mouslander
Level 4

17-10-2018

great. Glad it worked out for you.

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile
shawnFMU
Level 1

16-10-2018

It works!

turns out you need to set your input field as a Date/Time Field, BUT leave the Patterns setting empty.

I guess the script takes whatever default setting the Date/Time Field uses... go figure... seems counter intuitive to me...

Thank you very much mouslander!

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile

mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

27 solutions
View profile
mouslander
Level 4

15-10-2018

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile

shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

1 solution
View profile
shawnFMU
Level 1

15-10-2018

sorry. No luck here. straight copy and paste. formCalc check;  "dynamic" check; "calculate" event check;

- syntax double checked... to my best abilities...

- wrote out the references... "form1.Page1.Time1.formattedValue"

I tried with normal Text Field.

then flipped to a Date/Time Field with time set in the binding. a normal pattern selected in the display tab.

"0" is displayed in the total field... that's good.

what's your Fields like? Text or Date/Time?

how are you inputting your value? "12" & "1" or "12:00" & "1:00"

So, I imagine Time2Num is taking a time formatted value and converting it to a numeric value... and

Num2Time is numeric value to a time format...?