Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Juggernaut

Featured Replies

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.

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

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

:)

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:

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

  • Author

LaRetta,

That was just what I was looking for. Short and sweet. And I like the Boooo part too.

Thank you all.

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

Lee

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.