elanahy Posted March 6, 2007 Posted March 6, 2007 It seams this is very simple so I know I'm just missing something. I want to check a global date field to check that it is valid. I'm entering it in a message box. Is there a function for this? For example if I enter the date 2/29/2009 it should not allow it instead it just deletes it automatically. Any invalid date like 13/13/2007. I have error capture off.
jamesducker Posted March 6, 2007 Posted March 6, 2007 In FileMaker, many more dates are 'valid' than you would expect. This is because FileMaker assumes that if you enter, say, "32nd December 1999" you mean "1st January 2000". This is handy if you want to do simple calculations like "due date = invoice date + 30" as it saves you fiddling around with days left in the month, days in to the following month etc. To test whether your date is valid, you'd need to make FileMaker work out the date as it thought best, then see if the day/month/year it evaluated were the same as the day/month/year you put in. If they're not, then FileMaker has done some trickery on your behalf, so the date input must not have been strictly valid. You could define a calculation field (or a calculation within a script) as: let($month=2; let($day=29; let($year=2009; let( evaluatedDate = date($month;$day;$year) ; if( year(evaluatedDate)=$year and month(evaluatedDate)=$month and day(evaluatedDate)=$day ; "Valid" ; "Not valid") )))) If you try the above with different values set for $day, $month and $year at the top, you'll see that it works. If you are getting the date from a text field called "inputDate" that was formatted for example "02/29/2009", you'd probably need to alter the first three lines of the calculation to: let($month=left(inputDate,2); let($day=middle(inputDate,4,2); let($year=right(inputDate,4); In practice you should also include some trapping to make sure the user entered the date in the expected format... Does that help? James
LaRetta Posted March 6, 2007 Posted March 6, 2007 Global date field? Script test after User enters the date via Custom Dialog ... If [ not IsValid ( table::globalDate ) ] Show Message [ OK; BOOOOOOO! ] Halt Script End If :)
LaRetta Posted March 6, 2007 Posted March 6, 2007 I was in a hurry ... you would, of course, provide User a way to correct their entry by bringing up another dialog. But I liked the BOOOOOOO much better. :wink2:
comment Posted March 6, 2007 Posted March 6, 2007 FileMaker assumes that if you enter, say, "32nd December 1999" you mean "1st January 2000". I am afraid that only applies to the Date() function - not to a date field. A date field, global or not, will NOT accept a DIRECT entry of an invalid date. However, it IS possible to enter an invalid date indirectly, for example by importing, or thru a custom dialog. Such entry will NOT be automatically corrected to a valid date. As LaRetta said, the simplest way to test for a valid date is by using the IsValid() function, for example: Show Custom Dialog [ Buttons: “OK”, “Cancel”; Input #1: Table::gDate ] Loop Exit Loop If [ IsValid ( Table::gDate ) ] Show Custom Dialog [ Message: "The date you have entered is not a valid date."; Buttons: “OK”; Input #1: Table::gDate ] End Loop
elanahy Posted March 7, 2007 Author Posted March 7, 2007 LaRetta, That was just what I was looking for. Short and sweet. And I like the Boooo part too. Thank you all.
Lee Smith Posted March 7, 2007 Posted March 7, 2007 Why not include the Calendar that is available in layout mode in Field Format? Lee
Recommended Posts
This topic is 6533 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