is a date broke?

Sarah Reichelt sarah.reichelt at gmail.com
Tue May 1 23:54:08 EDT 2007


On 5/2/07, Chipp Walters <chipp at chipp.com> wrote:
> Sarah,
>
> Do you have any date validator functions laying around. If so, could
> you pour me a cupful? Thanks ;-)

Hi Chipp,

Here is one I use sometimes. If the supplied date is OK, it returns
that date as a short date but with the year as 4 digits, however you
can easily modify that. The parameter must be in English format.

It uses 2 methods: firstly checking whether the supplied date can be
converted to dateItems and then assembling those items into a short
date and seeing if that converts to the same seconds as the supplied
date.

The only peculiarity I have found is that negative years will work.
year -1 becomes 1999 and so on.

function checkDate pDate
    put pDate into formDate
    convert formDate to dateItems
    if the number of items in formDate <> 7 then return "error"
    put item 2 of formDate & "/" & item 3 of formDate & "/" & item 1
of formDate into formDate
    put formDate into formSecs
    convert formSecs to seconds
    convert pDate to seconds

    if formDate is a date and formSecs = pDate then
        return formDate
    else
        return "error"
    end if
end checkDate

My preferred method of date validation is not to allow direct date
entry but only to let people choose a date from a calendar. There is
one on my web site which anyone is welcome to use
<http://www.troz.net/Rev/libraries.php>.

Cheers,
Sarah



More information about the use-livecode mailing list