Brian Dunning's FileMaker Custom Functions

FormatDateAsText ( baseDate ; Format )

Formats a date with a specifiable format

  Average rating: 4.6 (35 votes) Log in to vote

Eilert Sundt   Eilert Sundt
Eilert Sundt Systemdesign
http://www.eilert.no

Share on Facebook Share on Twitter

  Sample input:
FormatDateAsText( Date(9;30;2009) ; "YYYY-MM-DD" )
FormatDateAsText( Date(9;30;2009) ; "M/D/YY" )
  Sample output:
2009-09-30
9/30/09

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This custom function takes as input a date and a text representation of a date format and returns a formatted date as a text string.
The following formatting strings are supported:
M
MM
D
DD
YY
YYYY

 

Comments

Maarten   Maarten, Private
Sep 30, 2009
I couldnt get that to work as advertised.

Shouldn't it be something like this

// DateAsText ( TheDate ; Format )
// Supports YYYY and YY, MM and M ; DD and D formats
// separators should be set in Format (use a value list)
// not recursive

Let
(
[
TheYear = Right ( Year ( TheDate ) ; PatternCount (Format ; "Y") ) ;

TheMonth = Case ( Month ( thedate ) ≤ 9 ; Right ( "00" & Month ( thedate ) ; PatternCount ( Format ; "M" ) ) ; Month ( thedate ) ) ;

TheDay = Case ( Day ( thedate ) ≤ 9 ; Right ( "00" & Day ( thedate ) ; PatternCount ( Format ; "D" )) ; Day ( thedate ) ) ;

Simplified = Substitute ( Format ; ["YY" ; "Y" ] ; ["YY" ; "Y" ] ; ["MM" ; "M" ] ; ["DD" ; "D" ] )

] ;

Substitute ( Simplified ; [ "Y" ; TheYear ] ; [ "M" ; TheMonth ] ; [ "D" ; TheDay ] )
)
 
Eilert Sundt   Eilert Sundt, Hammerfest, Norway
Nov 9, 2009
Sorry for returning to this so late. I accidentally pasted the wrong code initially. It should work now.
 

Log in to post comments.

 

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

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: