Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6533 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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.

Posted

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

Posted

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

:)

Posted

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:

Posted

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

Posted

Why not include the Calendar that is available in layout mode in Field Format?

Lee

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.