I've got most of the essentials for a project I'm building but I'm having an issue with rounding timestamps.

I have a button that when pressed enters into the field the current timestamp. But it inevitably ends up with something like:

16/05/2016 10:02:07

The tricky thing is that I want the minute to be either a 0 or a 5 but I'm not sure how I would do that.

Typical rounding would be to round it to 10:00 but it gets a little tricky for other fields so I'll describe this in detail a little bit more now.

So I have the following fields:

Start Travel

Onsite

Offsite

End Travel

Now if Start Travel was 10:02 then I'd want it to be rounded to 10:00 but if it took me 1 minute to get to site which in this case would make Onsite 10:03 then I don't want it to round down to 10:00 otherwise the time would be 0 minutes so I would want it to round UP to make the time 10:05.

Obviously there would need to be some checking of the previous field in order to round up (or maybe not you'd just round the time up regardless I guess) but in any case I don;t know how I'd do it. Does it need to be converted to numbers then the result displayed as timestamp or what?

Thanks for your help.

You've presented a specific example and the result you want which is helpful, but I'm not 100% sure if I understand the "general rule" is. I'm assuming it's:

Start Travel: Round down to the nearest 5 min increment

Onsite: Round up to the nearest 5 min increment that is greater than Start travel

Offsite: Round up to the nearest 5 min increment that is greater than Onsite

End travel: Round up to the nearest 5 min increment that is greater than Offsite

Does that seem accurate? If so, then:

Start travel =Let ( [

//minimum interval is 300 seconds aka 5 minutes times 60 seconds

interval = 5 * 60 ;

ts = get ( CurrentTimestamp ) ;

ts.div = ts / interval ;

ts.round =Floor ( ts.div ) ;

ts.new = ts.round * interval ;

result = GetAsTimestamp ( ts.new )

] ;

result

)

Onsite:Let ( [

interval = 5 * 60 ;

start.travel = table::Start Travel

actual.ts = Get ( CurrentTimestamp ) ;

//use the greater of the interval or the actual time elapsed.

ts = Max ( start.travel + interval ; actual.ts ) ;

ts.div = ts / interval ;

ts.round = Ceiling ( ts.div ) ;

ts.new = ts.round * interval ;

result = GetAsTimestamp ( ts.new )

];

result

)

Etc etc.

OffsiteandEnd travelare the same calc asOnsite, except replace table::Start Travel with the previous event's field name.*edited to corrected an error