Hello,
I have a meeting form which needs to have the finish time calculated from a start time and allocated time (in minutes).
The allocated time is a text field with the default of "00:00". The user can then enter the number of minutes for the agenda item to take. eg 00:20 would be 20 minutes.
The start time is a date/time calculated field which shows the current time after the allocated time has been entered. The formcalc script is :
form1.ActionsHeaderFrame.ActionsStartTime.rawValue
= num2time(Time(), TimeFmt(1))
The Finish Time field is a calculated date/time field to add up the start time and allocated minutes.
The formcalc script is:
var Min1 = ActionsTime.rawValue
var Start1 = Time2Num(ActionsStartTime.formattedValue, "h:MM A")
form1.ActionsHeaderFrame.ActionsEndTime.rawValue = Min1 + Start1
The end time is showing as a number, and I need help in converting to a time.
An example is as follows:
If the text field for allocated time as 00:20 and the start time date field shows 4:23 PM the calculated End time field is showing 22980001.
Any advice or assistance with this script would be most appreciated.
Solved! Go to Solution.
Views
Replies
Total Likes
Sorry Jo,
When I tested I didn't use a whole hour. One of the time patterns was incorrect for the Start time (the Edit pattern).
Here is the form, hopefully working: https://acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA
I have used the time.short{} pattern and would recommend this.
Good luck,
Niall
Views
Replies
Total Likes
Hi,
If you use the Num2Time function to change the calculated value back to a time. Eg this Formcalc in a Date/Time field, which is set to a Time format in the Object > Binding tab:
$ = Num2Time((Min1 + Start1), "H:MM A")
Should give you the time.
Niall
Sorry - engage brain ;-)
It looks like you are adding two different things - a value of "20" minutes AND time data converted into milliseconds.
So I would recommend turning the allocated time into a date/time field, set to a time format in the Object > Binding. Then in the script you would calculate the number of milliseconds using theTime2Num function, giving the allocated time in milliseconds. Then you can add the two sets of data (Start time and Allocated time) in milliseconds and convert the answers back to time (Finish time).
If you are using dates and times then it is better to use the date/time object.
Phew,
Niall
Views
Replies
Total Likes
Thank you very much for your assistance.
I have changed the allocated time field (ActionsTime) to a binding time field.
In the End Time Field (ActionsEndTime) I have changed the formcalc function as follows:
var Min1 = Time2Num(ActionsTime.formattedValue, "HH:MM")
var Start1 = Time2Num(ActionsStartTime.formattedValue, "h:MM A")
$ = Num2Time((Start1 + Min1), "H:MM A")
The result with user input:
Allocated time field input of 00:10 which is equal to (10 minutes)
Start time field 10:41 AM
End time Field result shows 23:51 PM
Can you please advise where the formula needs to be revised to show the correct end time?
Thank you
Views
Replies
Total Likes
Hi,
I have a sample here: https://acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA
In doing this I would propose a change in direction.
The Time2Num converts the time to milliseconds from the epoch.
So for the allocated time I have used a numeric field and instructed the user to input the time in minutes.
The Num2Time calculation then converts the allocated time from minutes to milliseconds and adds this to the start time, then converts back to a time.
So: use time field for time of day, but use a numeric field for duration.
Hope this helps,
Niall
Hi Niall. This is a form that would be very useful to me as well, however I can't get it to work right. If I enter 16:00 (which changes to 4:00pm) for the Start Time and 1 minute for the Allocated Time, it calculates 8:01pm for the Finish Time. Does it do this for you as well?
Jo
Views
Replies
Total Likes
Sorry Jo,
When I tested I didn't use a whole hour. One of the time patterns was incorrect for the Start time (the Edit pattern).
Here is the form, hopefully working: https://acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA
I have used the time.short{} pattern and would recommend this.
Good luck,
Niall
Views
Replies
Total Likes
Perfect!! Thank you very much!
Jo
Views
Replies
Total Likes
Thank you very much for the working sample.
I have been able to revise my form so that after the allocated time is entered (numeric field), the start time field will populate with the current time and the end time will populate with the finished time.
var vStart = Time2Num(ActionsStartTime.formattedValue, "h:MM A")
var vTime = ActionsTime * 60 * 1000
var vFinish = vStart + vTime
if (HasValue(ActionsTime) & HasValue(ActionsStartTime) ) then
$ = Num2Time(vFinish, "HH:MM")
else
""
endif
Your help and assistance is very much appreciated, thank you once again.
Views
Replies
Total Likes
Views
Likes
Replies