Re: how to test a string for a valid date in sql
From: Kay Kanekowski <kay.kanekowski_at_web.de>
Date: Fri, 11 Dec 2009 17:24:06 +0100
Message-ID: <hftrnb$kfp$03$1_at_news.t-online.com>
yossarian schrieb:
> Kay Kanekowski wrote:
>
>
> perl?
}
}
Date: Fri, 11 Dec 2009 17:24:06 +0100
Message-ID: <hftrnb$kfp$03$1_at_news.t-online.com>
yossarian schrieb:
> Kay Kanekowski wrote:
>
>> The example of yossarian shows you the way in perl.
>
> perl?
ok, the example in the link. i suppose it is perl.
sub isvaliddate {
my $input = shift;
if ($input =~ m!^((?:19|20)\d\d)[- /.](0[1-9]|1[012])[-
/.](0[1-9]|[12][0-9]|3[01])$!) {
# At this point, $1 holds the year, $2 the month and $3 the day of the date entered
if ($3 == 31 and ($2 == 4 or $2 == 6 or $2 == 9 or $2 == 11)) { return 0; # 31st of a month with 30 days } elsif ($3 >= 30 and $2 == 2) { return 0; # February 30th or 31st } elsif ($2 == 2 and $3 == 29 and not ($1 % 4 == 0 and ($1 % 100 != 0 or $1 % 400 == 0))) { return 0; # February 29th outside a leap year } else { return 1; # Valid date } } else { return 0; # Not a date
}
}
Kay Received on Fri Dec 11 2009 - 10:24:06 CST