FastDateInput ( )

Function stats

Average user rating
37
93
9999
Support
FileMaker 7.0 +
Date posted
05 December 2008
Last updated
11 March 2010
Version
Recursive function
Yes

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

FastDateInput  ( _input;   _format )


Parameters

_input  an input text field


_format  boolean. 1 for MM/DD/YY, 0 for DD/MM/YY


Description

Tags:  interface   format   date  

the purpose of this function is to allow user to input dates faster so please note that its name is extremely relevant ;-)

it handles the date format wether you are using international format (dd/mm/yyyy) or
American format (mm/dd/yyyy). Format must be set to 1 or “USA” to use American format.

User can now type : (let’s say system format is set to international)
- 12/07/1998
- 12/7/98
- 12/1998 : this return 12/01/1998
- 120798
- 12078 : this returns 12/07/2008
- 1207 : this returns 12/07/2006 (2006 being current year)
- 12 : returns 12/07/2006 (07/2006 being current month)
- toto : this is an error and will be colored

Examples

Sample input

FastDateInput ( 120798 ; 0 )


Sample output

07/12/98

 

Function code

/*
FastDateInput ( _input ; _format )
v. 2.0, May 2008
by Fabrice Nordmann
http://www.1-more-thing.com

2.0, may 2008 - evaluates expression if // found ("//-3" = three days before today)
1.2, april 2007 - formats a 2-1-2007 into 2/1/2007
1.1 now allows date as MM/YYYY or M/YYYY (will be understood as first of month)
1.0 july 2006

the purpose of this function is to allow user to input dates faster so please note that its name is extremely relevant ;-)

it handles the date format wether you are using international format (dd/mm/yyyy) or
American format (mm/dd/yyyy). Format must be set to 1 or “USA” to use American format.

User can now type : (let’s say system format is set to international)
- 12/07/1998
- 12/7/98
- 12/1998 : this return 12/01/1998
- 120798
- 12078 : this returns 12/07/2008
- 1207 : this returns 12/07/2006 (2006 being current year)
- 12 : returns 12/07/2006 (07/2006 being current month)
- toto : this is an error and will be colored

-------------------------------------
*/
Case ( PatternCount ( _input ; "//" )
; Let ([ _input = Substitute ( _input ; "//" ; "+" & GetAsNumber ( Get ( CurrentDate ))) ]; GetAsDate ( Evaluate ( _input )))
; Let ([
_input = Substitute ( _input ; "-" ; "/" )
; _digits = Filter ( _input ; "1234567890 .-;,/")
; _pattern = Substitute ( _digits ; [ "1" ; "#"] ; [ "2" ; "#"] ; [ "3" ; "#"] ; [ "4" ; "#"] ; [ "5" ; "#"] ; [ "6" ; "#"] ; [ "7" ; "#"] ; [ "8" ; "#"] ; [ "9" ; "#"] ; [ "0" ; "#"] )
; _blanks = Substitute ( _digits
; [ "/" ; " " ]
; [ ";" ; " " ]
; [ "," ; " " ]
; [ "." ; " " ]
; [ "-" ; " " ])
; _noSep = Substitute ( _blanks
; [ " " ; "" ])
; _len = Length ( _noSep )
; _dateFormat = Case ( _format = 1 or _format = "USA" ; 1 ; 0 ) // US format = 1 ; rest of the World = 0
; _monthpos = Case ( _dateFormat = 1 ; 1 ; 2 )
; _daypos = Case ( _dateFormat = 1 ; 2 ; 1 )
; _yNotCorrected =
Case (
WordCount ( _blanks ) = 3 ; RightWords ( _blanks ; 1 )
; _len = 8 ; Right ( _noSep ; 4 )
; _len > 4 ; Right ( _noSep ; _len - 4 )
; Year ( Get ( CurrentDate ))
)
; _y =
Case (
Length ( _yNotCorrected ) = 4 ; _yNotCorrected
; _yNotCorrected + 2000 > Year ( Get ( CurrentDate )) + 30 ; _yNotCorrected + 1900
; _yNotCorrected + 2000
)
; _m =
Case (
WordCount ( _blanks ) = 3 ; MiddleWords ( _blanks ; _monthpos ; 1 )
; _len < 3 ; Month ( Get ( CurrentDate ))
; Case ( _monthpos = 1 ; Left ( _noSep ; 2 ) ; Middle ( _noSep ; 3 ; 2 ))
)
; _d =
Case (
WordCount ( _blanks ) = 3 ; MiddleWords ( _blanks ; _daypos ; 1 )
; _len < 3 ; _noSep
; Case ( _daypos = 1 ; Left ( _noSep ; 2 ) ; Middle ( _noSep ; 3 ; 2 ))
)
];
Case (
IsValid ( GetAsDate ( _input ) ) ; TextColorRemove ( GetAsDate ( _input )) // if date was correctly entered, leave it
; ( _pattern = "##/####" or _pattern = "#/####" ) and IsValid ( GetAsDate ( FastDateInput ( "1/" & _input ; _format ))) ; FastDateInput ( "1/" & _input ; _format ) // date was entered as month/year
; IsValid ( Date ( _m ; _d ; _y )) ; TextColorRemove ( Date ( _m ; _d ; _y ))
; TextColor ( _input ; RGB ( 255 ; 0 ; 0 ))
)
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/93

    Prototype: FastDateInput( _input; _format )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 11 March 2010
    Version: 1.2

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (12)
Layout Objects  (11)
Filter  (11)
Design  (10)
Array  (7)