in reply to Validating Dates

timelocal doesn't exit on invalid date. It dies which can be trapped with eval. Also please note that timelocal doesn't die for some invalid dates. So it is good idea to check if localtime(timelocal(...)) returns same date.

I've been using this subroutine in my code to validate dates:

# checks if date is valid sub validate { use Time::localtime; use Time::Local qw(timelocal_nocheck); my $day = $shift; my $month = $shift; my $year = $shift; my $local; eval { $local = localtime(timelocal_nocheck(0, 0, 0, $day, $month - 1, $year)); }; if($@) { if($@ =~ /^Can't handle date/) { return 0; } else { die $@; } } my $c_day = $local->mday; my $c_month = $local->mon + 1; my $c_year = $local->year + 1900; return($day == $c_day and $month == $c_month and $year == $c_year) +; }

--
Ilya Martynov (http://martynov.org/)