7 Replies Latest reply on Aug 18, 2016 9:55 PM by jriley

# Enter Time Values in 15 Minute Increments

I want all time entered for a given time stamp field to be on the quarter hour. When a new record is created the auto entered time should be the current time rounded to the nearest 15 minutes and then be adjustable in 15 minute increments by using the up and down arrow keys.

Thoughts on how I can accomplish this?

• ###### 1. Re: Enter Time Values in 15 Minute Increments

You can use this formula in AutoEnter to get a timestamp of the current date/time rounded to the nearest 15 minutes:

Timestamp ( Get ( CurrentDate ) ; Time ( Hour ( Get ( CurrentTimestamp ) ) ; Round ( Minute ( Get ( CurrentTimestamp ) ) / 15 ; 0 ) * 15 ; 0 ) )

You would then use an OnObjectKeystroke script trigger on the field to trap for the arrow keys and adjust the time accordingly:

If [ Get ( TriggerKeystroke ) = 29 /* up arrow */]

Set Field [ Table::TimeStampField ; Table::TimeStampField + 900 ]

Else If [ Get ( TriggerKeystroke ) = 31 /* down arrow */]

Set Field [ Table::TimeStampField ; Table::TimeStampField - 900 ]

End If

1 of 1 people found this helpful
• ###### 2. Re: Enter Time Values in 15 Minute Increments

You can take a timestamp and round it to the nearest 15 minutes with a formula like this:

Let ( [

F1 = Get ( CurrentHostTimestamp ) ;

F2 = GetAsNumber ( F1 ) ;

F3 = 15 * 60 ;  // seconds in a 15 min period

F4 = F2 / F3 ;

F5 = Round ( F4 ; 0 ) ;

F6 = F5 * F3 ;

F7 = GetAsTimestamp ( F6 )

] ; F7 )

You can just have a positive and negative button next to it to move the timestamp up 15 minutes by adding or subtracting ( 15 * 60 ) to the timestamp.  Timestamps are all done in seconds is why you multiple by 60.

1 of 1 people found this helpful
• ###### 3. Re: Enter Time Values in 15 Minute Increments

I didn't see your reply, Philip, until I had posted mine.  Nice on the capturing the up and down arrow keys!

• ###### 4. Re: Enter Time Values in 15 Minute Increments

No, problem. Your formula for rounding the timestamp is better than mine anyway :-) (treating it as a number rather than rebuilding it piece by piece)

• ###### 5. Re: Enter Time Values in 15 Minute Increments

Thank you so very much!!

To get the arrow keys to work I made a minor adjustment:

If [ Code(Get ( TriggerKeystroke )) = 29 /* up arrow */]

Set Field [ Table::TimeStampField ; Table::TimeStampField + 900 ]

Else If [ Code(Get ( TriggerKeystroke )) = 31 /* down arrow */]

Set Field [ Table::TimeStampField ; Table::TimeStampField - 900 ]

End If

• ###### 6. Re: Enter Time Values in 15 Minute Increments

Ah yes, good clarification.

• ###### 7. Re: Enter Time Values in 15 Minute Increments

I like this method for its simplicity

GetAsTime ( Round ( Get ( CurrentTime ) / 900 ; 0 ) * 900 )