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.
There are 1,000 milliseconds/second
There are 60 seconds/minute.
There are 60,000 milliseconds/minute
There are 60 minutes/hour
There are 3,600,000 milliseconds/hour
So 3,600,000 is the number of milliseconds in an hour. Your answer is in hours. So the answer of 0.5 is 1/2 hour. To convert 1/2 hour to minutes you can multiply that value by 60 minutes/hour. Or you could divide the difference in milliseconds by 60,000 milliseconds/minute.
Adding comments and even the steps to compute the number milliseconds for a given time period might help other see and understand the computation.
// test for data for computation
if (HasValue(StartTime) and HasValue(EndTime)) then
// start time in milliseconds
var in_ = Time2Num(StartTime.formattedValue, "h:MM A")
// end time in milliseconds
var out_ = Time2Num(EndTime.formattedValue, "h:MM A")
// test that end is not before start
if (in_ >= out_) then
xfa.host.messageBox("The start time cannot be greater than or equal to the end time.")
$.rawValue = null
else
// compute the difference in milliseconds
var diff = out_ - in_
var Sec = 10000; // milliseconds in one second
var Min = 60 * Sec // milliseconds in one minute
$.rawValue = diff / min
endif
else
$.rawValue = null
endif
George Kaiser