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

SOLVED

Simple Time Duration Calculation

Avatar

Level 3

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;

Thank you in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

5 Replies

Avatar

Correct answer by
Level 7

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

Avatar

Level 3

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...?

Avatar

Level 7

Send me your email address and I will send you my sample

Avatar

Level 3

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!