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

TimeFormatAs ( theTime ; type12or24 )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.3  (49 votes)
  Discuss this Custom Function

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

Formats time data as 12 or 24 hour time at the data level, rather than field format display level. Especially useful for users that desire 12-hour formatted time data.

Sample Input:
TimeFormatAs ( "10:30 AM" ; 24 )
TimeFormatAs ( "00:30:00" ; 12 )
TimeFormatAs ( "16:00" ; 12 )
TimeFormatAs ( "4:23 PM" ; 24 )
Sample Output:
"10:30:00"
"12:30 AM"
"4:00 PM"
"4:23 PM"


 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:

Modification Date: 4/12/2010
- Fixed behavior for better consitency due to changes in Time calculation results in FileMaker over the last few Versions (8-11).
- Fixed bug, reported by Will Loving: in 24 hr mode, "4:23 PM" time returned "4:23 PM" rather than the expected "16:23:00".
- Tweaked behavior to better handle valid FileMaker times like 11:65:65, to add extra any overage amounts of lesser time parts to their higher counterparts correctly, to make it a clock-compatible time, 12:06:05.
- Made separator between AM/PM and time a variable for easy output tweaking.

Modification Date: 2/12/2012
- Fixed behavior for better consitency due to changes in Time
calculation results in FileMaker over the last few Versions (8-11).
- Fixed bug, reported by Will Loving: in 24 hr mode, "4:23 PM" time returned "4:23 PM"
rather than the expected "16:23:00".
- Tweaked Behavior to better handle valid Filemaker times like 11:65:65, to add extra
overage amounts of lesser time parts to their higher counter parts correctly, to
make it a clock-compatible time.
- Made separator between AM/PM and time a variable for easy output tweaking.

Modification Date: 12/3/2012
- Escaped blank theTime input, was defaulting to 12AM.
- Fixed input parameter name not being correctly placed into theTime, variable.
- Renamed Time Input from timeField to theTime, since it doesn't require a field to use.

NOTE: Due to changes in the way FileMaker handles Time in calculations, there may be circumstances where you will find it difficult to get FileMaker to "display" the time as you intended. This calc will help, and in most cases it is all you need -- but if you are having problems, try looking at the custom function's results in the data viewer, or a text field, to see the actual results, rather than a time field.
--------------------

This function formats any valid FileMaker Pro time value by the format specified in the function's parameter allowing the user to convert from any time format to 12 or 24 hour time. This is useful because calculated time data results are always returned in FileMaker Pro's native "24 hour" time format.

As of version 7, this is compatible with Set Field, where previous versions were limited to using a Paste Result [calculated].

Though "Field Formatting" on a layout can format the time data in a nice 12 hour format when viewed onscreen, the nicely presented time reveals it's true 24 hour nature if a user clicks into the field (they will see "0:30" instead of "12:30 AM"). In the case of our the example above, any 12 hour formatted value lists will also fail to "open scrolled to" the proper "12:30 AM" value.

You can return a specific Time format if you wrap any time calculations you use with this function and you will know the user will see "nice 12 hour" time, this also works nicely on time fields with Auto-Enter and overwrite existing values set to "on".

NOTES:
Some changes to the AM/PM variables or other formatting options within the function may be necessary to make this compatible with other language/time settings for solutions run on systems that do not use U.S. 12-hour time formatting.

This function is not designed to espouse 12 hour time over 24 (or Military Time), but many users are disconcerted when data appears to have "lost its formatting," just because the system performed a calculation upon it.

----------------------
Parameters:

theTime - The time value to convert. The function only needs a time that is recognized by FileMaker Pro, and does not have to be the opposite of the desired converted result. (Thus if you are converting to 12 hour you *do not have to* provide a 24 hour formatted time.

type12or24 - The desired time format of the time result. The expected values are either 12 or 24, the default method is 12 Hour. Null or any value less than 24 will default to return a 12 hour time result .

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:

5 most recent comments | Show all 15 comments

Thanks Jason, I missed that documentation change. The comment now matches the function parameter name.

Jonathan, Van Nuys, CA
January 22, 2013 5:56pm

Is there a way to suppress the seconds from the output? To be quite honest, I'm being a bit lazy and haven't read through the code in the script. I'm merely looking for an easy way to take a time field and output it in a 12 hour format.

Tom, Leland, NC
October 01, 2015 12:57pm

Yes Tom, for the 12 hour time it's a little easier to do. Towards the bottom of the calculation you will see a Result12 variable... Towards the end of the case statements found inside that variable, you'll see the seconds section, which you can delete or modify with a variable to make it optional.

Hope that helps!
Jonathan

Jonathan Mickelson, Los Angeles
October 01, 2015 10:04pm

Thanks and sorry for being lazy. I've been swamped and took the easy way out. Have a great weekend!

Tom, Leland, NC
October 02, 2015 12:49pm

If you do things incrementally...and MUST be able to create schedules and show BOTH or EITHER US or MILITARY for various items....

Format the field for TIME.
in Inspector Choose DATA and Format TIME as ENTERED.

Use a drop down menu for various times of the day US and MILITARY included in dropdown list.

Drop Down menu example in 15 min increments:

US LIST
-------------------------
00:00am
00:15am
00:30am
00:45am

01:0 0am
01:15am
01:30am
01:45am

etc.

For our purposes during work daylight hours..first common used 12 hours are listed in a drop down.

06:00pm
06:15pm

listed all the way to...

07:45pm

08:00pm
------------------------

We don't change up schedules so quickly we do everythign in 15 min intervals..so we use 15 min.

For MILITARY...during work hours..I created more time options JUST BELOW the US...to handle the afternoon hours..so I add to my dropdown list to cover the afternoon hours....

MILITARY LIST
-----------------
13:00
13:15
13:30

etc...to go up to 7pm or 19:00

--------------------

It takes a bit to make the drop down list complete..but the beauty of it is you can copy the time and paste it in another time field...and it keeps that time at the same spot in the dropdown list..so you when you pull down...you are already in the spot on the list in the time frame you are working with...so for incremental additional or adding time slots...its easy and fast.

No issues with scripts, triggers...formatting..etc...Sort order works..Ascending.

Kimbakat, NYC
October 12, 2017 10:40am

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 6 + 7 =
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