Rewolfer Posted April 17, 2012 Posted April 17, 2012 I'm currently working on a complex validation of data-types. Since the input is text (coming thru JSON over the net) I have to make formal checks first, all of the following are considered valid dates: "14/11/2004" "11/14/2004" "2004-11-14" I thought I could rely on the FMP engine and let it check if this day actually existed and was rather shocked when I debugged my findings: IsValid ( Date ( 11 ; 14 ; 2004 )) => 1 IsValid ( Date ( 2 ; 30 ; 2003 )) => 1 (there is no 30th of February) IsValid ( Date ( 99 ; 99 ; 1999 )) => 1 (Maya calendar?-) The last entry is absurd. Date ( 99 ; 99 ; 1999 ) => 07/06/2007 When I try to input "99/99/1999" into a date field FMP complains like in GetAsDate ( "99/99/1999" ). But how am I supposed to check all the differently formated dates since GetAsDate ( "2004-11-14" ) is invalid as well? I found a workaround but wondered if this behaviour was intended. Thanks for any feedback. TSW.
comment Posted April 17, 2012 Posted April 17, 2012 I am afraid you are missing an important purpose of the Date() function: to calculate a date out of the given elements. The result of Date ( 2 ; 30 ; 2003 ) is the (valid) date of March 3, 2003. There is indeed no 30th of February, so the Date() function calculates the date that is 30 days later than February 1. This is what gives the Date() function its real power. To check that a text string represents a valid date, try = IsValid ( GetAsDate ( YourTextDate ) ) Note that the result depends on the date format being used by the file: IsValid ( GetAsdate ( "2/28/2003") ) will return true if the file uses m/d/y date format, false otherwise.
Recommended Posts
This topic is 4661 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now