Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

TimeRound ( theTime ; increment ; forceUpDn )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.2  (41 votes)
  Discuss this Custom Function

Jonathan Mickelson, Thought Development Corp.
http://thought-dev.com

Rounds a time field by a time interval and allows optionally forcing the rounding up or down

Sample Input:
TimeRound ( "10:25:00" ; "00:10:00" ; "" )
TimeRound ( "10:24:59" ; "00:10:00" ; "" )
TimeRound ( "00:03:59" ; "00:01:00" ; -1 )
TimeRound ( "03:00:02" ; "01:00:00" ; 1 )
TimeRound ( "03:00:02" ; "01:00:00" ; "up" )
Sample Output:
10:30:00
10:20:00
00:03:00
04:00:00
04:00:00


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

Function: TimeRound ( theTime ; increment ; forceUpDn )

Description: This function rounds a time field by a dynamic incriment
value, with the option to force it to round up or down, or
by default it uses normal rounding. Normal rounding defines
the breakpoint at 50% of the incriment value.

Output Format: a time value representing the rounded time.

See the following examples:
- TimeRound ( "10:25:00" ; "00:10:00" ; "" ) = "10:30:00"
- TimeRound ( "10:24:59" ; "00:10:00" ; "" ) = "10:20:00"
- TimeRound ( "00:03:59" ; "00:01:00" ; -1 ) = "00:03:00"
- TimeRound ( "03:00:02" ; "01:00:00" ; 1 ) = "04:00:00"
- TimeRound ( "03:00:02" ; "01:00:00" ; "up" ) = "04:00:00"
Parameters:

timeField - A time value to round.

increment - A time value representing the interval to round by. A Null, "" or
0 value will use Normal rounding. A positive number will force
the rounding to round up to the next highest increment, a negative
number will force the rounding to drop to the next lowest increment.

forceUpDn - A number value (or one of two thee values; up, dn or down )
representing desired rounding type to be used. A Null, "" or
0 value will use Normal rounding. A positive number, or "up", will
force the rounding up to the next highest increment, a negative
number, or "dn" or "down", will force the rounding to drop to
the next lowest increment.

Author - Jonathan Mickelson
Last Modified: 12/3/2012
- Wrapped both time-based inputs in GetAsTime (), to better type the inputs for the rest of the calc.
- Pre-processing short circuit to bypass empty times so it doesn't force 12:00 am.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

There is an error in the incr input variable. It should read into the function as date. For example, if you use the function as is with the incr input of "00:10:00" the value of typeAdj will be 500. If the input is GetAsTime ("00:10:00") the value of typeAdj will be 300. This correctly rounds the result. The change is in the initialization of p2. The updated calc appears below:

// TimeRound ( theTime ; incriment ; forceUpDn )

Let (
[
p1 = theTime ;
p2 = GetAsTime ( incriment ) ; // <-- THIS IS THE UPDATED PART - JH
p3 = Lower ( ForceUpDn ) ;
time = p1 ;
inc = Case (
IsEmpty ( p2 ) ;
GetAsTime ( "00:00:01" ) ;
p2
) ;
type = Case (
IsEmpty ( p3 ) ; 0 ;
Substitute ( p3;
[ "up" ; "1" ] ;
[ "dn" ; "-1" ] ;
[ "down" ; "-1" ]
)
) ;
typeAdj = Case (
type > 0 ; inc * .99999999 ; // Round Up
type < 0 ; inc * 0 ; // Round Down
type = 0 ; inc * .5 // Round Normal
) ;
rnd = ( Int ( ( time + typeAdj ) / inc ) ) * inc ;
result = GetAsTime ( rnd )
] ;
Case (
not IsEmpty ( time ) ;
// RESULT
result
) // END CASE
) // END LET

Jeff Hough, Portland, OR
April 04, 2012 12:19pm

Thanks Jeff,

I always tend to use this with actual Time fields, so I'd never run into that!
I've updated the calc and wrapped both time-based inputs in GetAsTime (), since both require time values.

Best,
Jonathan

Jonathan, Van Nuys, CA
December 03, 2012 2:57pm

NOTE: you have "increment" misspelled!

Israel Golding, Lakewood, NJ
June 03, 2015 7:26am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 5 + 5 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions