Hi, I am trying to do a time calculation
If
Time is between 12:01 am -6:00 am then I would like the calculation to = 1
Time is between 6:01 am - 12:00 pm then I would like the calculation to = .75
Time is between 12:01 pm - 6:00 pm then I would like the calculation to = .50
Time is between 6:01 pm to 12:00 am then I would like the calculation to = .25
I have looked at a lot of forums and I just cannot get this to work. I am trying to calculate travel time.
Please help.
sara
Views
Replies
Total Likes
Doing time calculations is never as easy as it seems. There are functions provided in FormCalc that make it easier to do but basically getting a number to represent the time is needed to do comparisons. There us a Time2Num function that gets you the number of milliseconds that have past since a set time. Then you can do a proper comparison ....I included a sample that shows how to do it. The code is on the exit event of the Time Check field.
Hope that helps
Paul
Views
Replies
Total Likes
okay, how did you do that?
Views
Replies
Total Likes
Look at the code on the exit event of the Time Check field ......that shows the conversion of time to a number and then the if statements that are used to
determine which zone the time belongs to.
paul
Views
Replies
Total Likes
Hi Paul,
thank you so much for your help. but i am doing something wrong. it works on your form, but I cannot get it to work on mine. I changed factor to my field name and am I supposed to change anything else?
sorry for the trouble.
sara
Views
Replies
Total Likes
What format are you reporting the time in HH:MM:SS?
The function expects the time in a specific format. Are you getting any errors?
Paul
Views
Replies
Total Likes
no errors. from patterns it says hh:MM:SS A. I would upload the form so you could take a look at it but I can seem to figure out how to do that??
Views
Replies
Total Likes
Send it to LiveCycle8@gmail.com but I will not be able to look at it until tomorrow.
Paul
Views
Replies
Total Likes
Views
Replies
Total Likes
I got it!!!!!!!!!!!!!! took a lot of work but this is how i got the following
12:01 am - 6:00 am = 1
6:01 am - 12:00 pm =.75
12:01 pm - 6:00 pm = .50
6:01 pm - 12:00 am = .25
Thank you Paul for your formula.
if ((Time2Num(this.formattedValue) >= 36060001) & (Time2Num(this.formattedValue) <= 57600001)) then
Factor.rawValue = 1
endif
if ((Time2Num(this.formattedValue) >= 57660001) & (Time2Num(this.formattedValue) <= 79200001)) then
Factor.rawValue = .75
endif
if ((Time2Num(this.formattedValue) >= 79260001) & (Time2Num(this.formattedValue) <= 100800001)) then
Factor.rawValue = .5
endif
if ((Time2Num(this.formattedValue) >= 100860001) & (Time2Num(this.formattedValue) <= 122340001)) then
Factor.rawValue = .25
endif
Views
Replies
Total Likes