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
*/
// ===================================
/*__LITBR__FastDateInput ( _input ; _format )__LITBR__v. 2.0, May 2008__LITBR__by Fabrice Nordmann__LITBR__http://www.1-more-thing.com__LITBR____LITBR__2.0, may 2008 - evaluates expression if // found ("//-3" = three days before today)__LITBR__1.2, april 2007 - formats a 2-1-2007 into 2/1/2007__LITBR__1.1 now allows date as MM/YYYY or M/YYYY (will be understood as first of month)__LITBR__1.0 july 2006__LITBR____LITBR__the purpose of this function is to allow user to input dates faster so please note that its name is extremely relevant ;-)__LITBR____LITBR__it handles the date format wether you are using international format (dd/mm/yyyy) or__LITBR__American format (mm/dd/yyyy). Format must be set to 1 or “USA” to use American format.__LITBR____LITBR__User can now type : (let’s say system format is set to international)__LITBR__- 12/07/1998__LITBR__- 12/7/98__LITBR__- 12/1998 : this return 12/01/1998__LITBR__- 120798__LITBR__- 12078 : this returns 12/07/2008__LITBR__- 1207 : this returns 12/07/2006 (2006 being current year)__LITBR__- 12 : returns 12/07/2006 (07/2006 being current month)__LITBR__- toto : this is an error and will be colored__LITBR____LITBR__-------------------------------------__LITBR__*/__LITBR__Case ( PatternCount ( _input ; "//" )__LITBR__; Let ([ _input = Substitute ( _input ; "//" ; "+" & GetAsNumber ( Get ( CurrentDate ))) ]; GetAsDate ( Evaluate ( _input )))__LITBR__; Let ([__LITBR__ _input = Substitute ( _input ; "-" ; "/" )__LITBR__ ; _digits = Filter ( _input ; "1234567890 .-;,/")__LITBR__ ; _pattern = Substitute ( _digits ; [ "1" ; "#"] ; [ "2" ; "#"] ; [ "3" ; "#"] ; [ "4" ; "#"] ; [ "5" ; "#"] ; [ "6" ; "#"] ; [ "7" ; "#"] ; [ "8" ; "#"] ; [ "9" ; "#"] ; [ "0" ; "#"] )__LITBR__ ; _blanks = Substitute ( _digits__LITBR__ ; [ "/" ; " " ]__LITBR__ ; [ ";" ; " " ]__LITBR__ ; [ "," ; " " ]__LITBR__ ; [ "." ; " " ]__LITBR__ ; [ "-" ; " " ]) __LITBR__; _noSep = Substitute ( _blanks__LITBR__ ; [ " " ; "" ]) __LITBR__; _len = Length ( _noSep )__LITBR__; _dateFormat = Case ( _format = 1 or _format = "USA" ; 1 ; 0 ) // US format = 1 ; rest of the World = 0__LITBR__; _monthpos = Case ( _dateFormat = 1 ; 1 ; 2 )__LITBR__; _daypos = Case ( _dateFormat = 1 ; 2 ; 1 )__LITBR__; _yNotCorrected =__LITBR__ Case ( __LITBR__ WordCount ( _blanks ) = 3 ; RightWords ( _blanks ; 1 )__LITBR__ ; _len = 8 ; Right ( _noSep ; 4 )__LITBR__ ; _len > 4 ; Right ( _noSep ; _len - 4 )__LITBR__ ; Year ( Get ( CurrentDate ))__LITBR__ )__LITBR__; _y =__LITBR__ Case (__LITBR__ Length ( _yNotCorrected ) = 4 ; _yNotCorrected__LITBR__ ; _yNotCorrected + 2000 > Year ( Get ( CurrentDate )) + 30 ; _yNotCorrected + 1900__LITBR__ ; _yNotCorrected + 2000__LITBR__ )__LITBR__; _m =__LITBR__ Case (__LITBR__ WordCount ( _blanks ) = 3 ; MiddleWords ( _blanks ; _monthpos ; 1 )__LITBR__ ; _len < 3 ; Month ( Get ( CurrentDate ))__LITBR__ ; Case ( _monthpos = 1 ; Left ( _noSep ; 2 ) ; Middle ( _noSep ; 3 ; 2 ))__LITBR__ )__LITBR__; _d =__LITBR__ Case (__LITBR__ WordCount ( _blanks ) = 3 ; MiddleWords ( _blanks ; _daypos ; 1 )__LITBR__ ; _len < 3 ; _noSep__LITBR__ ; Case ( _daypos = 1 ; Left ( _noSep ; 2 ) ; Middle ( _noSep ; 3 ; 2 ))__LITBR__ )__LITBR__];__LITBR__Case (__LITBR__ IsValid ( GetAsDate ( _input ) ) ; TextColorRemove ( GetAsDate ( _input )) // if date was correctly entered, leave it __LITBR__; ( _pattern = "##/####" or _pattern = "#/####" ) and IsValid ( GetAsDate ( FastDateInput ( "1/" & _input ; _format ))) ; FastDateInput ( "1/" & _input ; _format ) // date was entered as month/year__LITBR__; IsValid ( Date ( _m ; _d ; _y )) ; TextColorRemove ( Date ( _m ; _d ; _y ))__LITBR__; TextColor ( _input ; RGB ( 255 ; 0 ; 0 ))__LITBR__)__LITBR__)__LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/93__LITBR____LITBR__ Prototype: FastDateInput( _input; _format )__LITBR__ Function Author: Fabrice (http://www.fmfunctions.com/mid/37)__LITBR__ Last updated: 11 March 2010__LITBR__ Version: 1.2__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.