3 Replies Latest reply on Jul 1, 2012 12:27 PM by GuyStevens

# calculations based on time

### Title

calculations based on time

### Post

I'm having trouble with time calculations. I want to compare a due out time with the current time, and flag it accordingly. I have:

Case (
Status  = "In planning" and (Get ( CurrentDate ) > Date out or (Date of return = Get ( CurrentDate ) and Get(CurrentTime) > (Time out + 7200)))
;"Hasn't left yet?";
(Date of return < Get ( CurrentDate ) or (Date of return = Get ( CurrentDate ) and (Time of return to camp + 7200)  > Get ( CurrentTime ))) and Status ≠ "Has returned"
;"Overdue")

(Text in red is the problem). "Time out" is a time field; the entry method is a value list which reads "12:30 PM, 1:00 PM, 1:30 PM..." etc. I want to compare that to the current time, with two hours (7200 seconds) leeway, to set the text. It doesn't work. How would one accomplish this?

• ###### 1. Re: calculations based on time

First of all you need to make sure your calculation is "Unstored" because you are using Get (CurrentDate) and (CurrentTime) you need to make sure these are always recalculated when needed.

Also: What is the role of the 2 hours? (7200 seconds)

I don't understand how an item "Hasn't left yet" when your current time is later then 2 hours after the time out?

I simplified your calc a little but left out the 2 hours leeway because I don't really understand what you want from it:

Case (
Status = "In planning"
and
Timestamp ( Get (CurrentDate ) ; Get (CurrentTime) )  ≤ Timestamp ( DateOut ; TimeOut )
;"Hasn't left yet?";
Status ≠ "Has returned"
and
Timestamp ( DateReturn ; TimeOfReturn )  <  Timestamp ( Get (CurrentDate ) ; Get (CurrentTime) )
;"Overdue")

• ###### 2. Re: calculations based on time

Thanks... I hadn't thought to use Timestamp, not having used it before.

The field is used as a prompt... as in, "You were scheduled to leave two hours ago... why are you still here?!" I'm giving a two hour leeway before having that prompt appear, hence the addition of 7200 seconds to the current time.Same idea applies to the return time and date.

So could you do that this way?

Case (
Status = "In planning"
and
Timestamp ( Get (CurrentDate ) ; Get (CurrentTime) + 7200)  ≤ Timestamp ( DateOut ; TimeOut )
;"Hasn't left yet?";
Status ≠ "Has returned"
and
Timestamp ( DateReturn ; TimeOfReturn )  <  Timestamp ( Get (CurrentDate ) ; Get (CurrentTime) )
;"Overdue")

• ###### 3. Re: calculations based on time

Adding seconds like that should work.

You can always test this by making a script that shows a custom dialogue that shows:

Get (CurrentTime) +7200

And see what the result is.