ashokpj has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I like to validate date value, below scripts will find if day is more the 31 days and month is more than 12. But this scripts incorrectly allow for february to have 31 days
please let me know which module support to validate date value(involved leap years ) and format.
use Time::Local; my ($sec,$min,$hour) = qw( 0 0 12 ); my ($mday, $mon, $year) = qw(31 02 2012); $mon--; # because that's how unix/C treat the month value eval { my $dummy = timelocal($sec,$min,$hour,$mday,$mon,$year); }; print $@; if (my $err = $@) { print "This is an invalid date."; } else { print "Yay"; };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Validate date value
by Punitha (Priest) on Oct 04, 2007 at 11:42 UTC | |
Re: Validate date value
by bart (Canon) on Oct 04, 2007 at 11:47 UTC | |
Re: Validate date value
by shmem (Chancellor) on Oct 04, 2007 at 11:57 UTC | |
Re: Validate date value
by svenXY (Deacon) on Oct 04, 2007 at 11:47 UTC | |
Re: Validate date value
by apl (Monsignor) on Oct 04, 2007 at 11:43 UTC |
Back to
Seekers of Perl Wisdom