Expand my Community achievements bar.

SOLVED

Need help with calculating start time and end time and placing the result in a duration text box as

Avatar

Level 2

I did a search on the forum for calculating start time and end time and  found the following code which I'm utilizing as a formcalc on the  duration field.
==============================================================
form1.Page1.Duration::calculate - (FormCalc, client)
 
if (HasValue(StartTime) and HasValue(EndTime)) then
var in_ = Time2Num(StartTime.formattedValue, "h:MM A")
var out_ = Time2Num(EndTime.formattedValue, "h:MM A")
if (in_ >= out_) then
xfa.host.messageBox("The start time cannot be greater than or equal to the end time.")
$.rawValue = null
else
var diff =  out_ - in_
$.rawValue = diff/3600000
endif
else
$.rawValue = null
endif
=============================================================
 
So when I enter a start time for example of 3:30 pm and end time of 4:00
 
The duration field will say 0.5
  
How can I get my form to say 30 minutes instead of placing a decimal number?
 
Secondly, how can I utilize LC patterns field where the employee can  just type 330 or 3:30 and it automatically based on the computer's clock  put in on the start time 3:30 PM?
 
Any help will be greatly appreciated.  Thank you.

Attached is the form for viewing:

https://acrobat.com/#d=f1kxh5qjuow5ujyZduF8OQ

1 Accepted Solution

Avatar

Correct answer by
Level 10

To display the results in a regular time format you can use:

$.rawValue = Num2Time(diff/3600000, "HH:MM")

For a flexible input of times check this example.

http://thelivecycle.blogspot.com/2011/05/flexible-eingabe-von-daten-und-zeiten.html

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

To display the results in a regular time format you can use:

$.rawValue = Num2Time(diff/3600000, "HH:MM")

For a flexible input of times check this example.

http://thelivecycle.blogspot.com/2011/05/flexible-eingabe-von-daten-und-zeiten.html