If you enter time as minutes in a number field, this calculation can be used to produce the end time of the event:
StartTime + 60 * EventTimeInMinutes
Select Time as the calculation's return type.,
This works because time fields store time as an integer that counts the number of seconds elapsed since midnight. All you have to do is compute the correct number of seconds to add to your start time.
Thanks again Phil, That worked like a charm.
Can I assume the If I were adding in Hours (rather than min's) would be:
StartTime + (360 * EventTimeInMinutes)
No ! There are 3600 seconds in an hour.
Whoops! Glad I asked.
IF you are adding hours and minutes to the same start time, you might want to just use a Time Field and then your calculation becomes:
StartTimeField + ElapsedTimeField
How would this be expressed as part of an IF statement in a script?
Exactly the same, but an If step requires a Boolean result value of True (Or number other than zero or null) or False (values Null or zero) will be expected in order to control which section of code is next executed.
You've given no indication as to how you would use such a calculation in a script but you might write it like this:
If [ ( StartTime + 60 * EventTimeInMinutes ) < GetAstime ( "12:00 pm" ) ]
This then checks to see if the calculated time falls before noon. Note the need to avoid comparing apples to oranges here. Since the calculation to the left of < is of type time, I need to compare it to a value of type time on the right. There are a number of different ways to get a value of type time, this is just one possibility here.
I'm looking to set a TargetDate from a Priority field.
If i format the cell as a calculation the above works perfectly. However there are 3 priorities.
1 - 4 hours
2 - 24 hours
3 - 28 days
I was originally just wanting to add the amount of seconds to CreateDate, to make TargetDate. I think I need a script to run on enter of TargetDate to read what is in Priority, and add the relevant number of seconds.
Then I realised this may not be feasible anyway as I need to miss out non business hours and days!
Dates store a number that's the number of days since 12/31/0000. Time fields store a number that's the number of seconds since midnight. So you can't use a time calculation with a date field.
What you need is a field of type TimeStamp. This field combines both a date and a time. It stores a value that's the number of seconds since midnight of 12/31/0000. So now you can add and subtract time from this value to get a result (Of type timestamp) that includes a date as well as a time.
You'll need all three priority values in seconds, not hours or days.
Case ( Priority = 1 ; 4 * 3600 ;
Priority - 2 ; 24 * 3600 ;
Priority = 3 ; 28 * 24 * 3600
Result type would be TimeStamp
You can also use Choose in place of case here. the syntax differs a bit, but it also works here.
I would not actually "hard code" the different time intervals and priorities into a calculation like this. I'd put this data in a table with one record for each priority and use an auto-enter calculation with a relationship to compute the TargetTimeStamp. That way, users can modify the priorities and time intervals by editing data in that table instead of needing a FileMaker developer to redefine the calculation.