4 Replies Latest reply on Feb 4, 2013 3:39 PM by johnhorner

    Determining If Text String Would Be A Valid Date

    johnhorner

      Title

      Determining If Text String Would Be A Valid Date

      Post

           i hope this is an easy one... is there a way to test to see if a string of text would constitute a valid date?  for example:

           "John Smith" (not valid)

           "Dec" (not valid)

           "07/15/13" (valid)

           the reason is because i have a global search field that the user can enter in search criteria.  a script then uses this criteria to look for matching records based on several different fields.  most of the fields are text fields and this works fine.  however, if i search for a match in a date field and use a string that is not valid, it fails.  so i want to determine if it is valid before using it to search any date fields.

           any thoughts much appreciated.

        • 1. Re: Determining If Text String Would Be A Valid Date
          philmodjunk

               Why not use a global date field for entering search dates? If it might be a date range, use two global date fields. By using fields of type date, Filemaker's built in validation routines will catch invalid dates for you.

          • 2. Re: Determining If Text String Would Be A Valid Date
            johnhorner

                 thanks phil.  the reason i am not doing that is because i am trying to use a single field (e.g. web browser style) where the user can enter in any criteria (a persons name, their birthday, their address, etc) and the script will find any potential matches.  so for example, someone could enter in "sam" and find anyone with "sam" in their first or last name or in the name of their street or city or they could enter "73" and find any records with a street address that contains "73".  but if i just create a new record/request and perform a find with "73" in a date field (like birthdate) then the script fails (currently with error capture on, it returns all records).  i only want to include a find on the birthdate field if what the user entered is actually a date. does that make sense?  i was hoping to find the easiest way to determine this by some sort of calculation.  it did occur to me to count the length of hte field and see if it had 2 "/" characters in it and then test the text to the left, center and right of the "/"s to see if htey fall within the appropriate ranges but i was hoping there was some sort of easier technique or ready made function to do this... am i out of luck?

            • 3. Re: Determining If Text String Would Be A Valid Date
              philmodjunk

                   GetasDate ( YoursearchField ) will return a quesiton mark if the text is not a valid date and just like entering a date in a date field, if you enter an expression such as 5/12, it will add the current year to the resulting value.

                   But I think I'd script the global field to use it with Quick Find instead of the script you are using. that would seem to make for a simpler script and one where the above test of whether the date is valid should not be needed.

              • 4. Re: Determining If Text String Would Be A Valid Date
                johnhorner

                     i will have to learn more about quick finds... i thought that was when you used the search "area" in the status toolbar (which is hidded in this solution). now that you suggested it, i looked and did just notice that there is a script step for perform quick find.  i think that is certainly going to simplify my script... thanks!  i had a feeling i was not approaching this the right way...