Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How do I validate a date?

by BaldPenguin (Friar)
on Nov 18, 2005 at 18:14 UTC ( [id://509891]=note: print w/replies, xml ) Need Help??


in reply to How do I validate a date?

I wanted to validate a date AND it's format, and wanted to allow any ISO standard formatted date. This may not be the most elegant, but it does work.
use Date::Parse; use Date::Manip qw(); sub is_valid_date_string { my $str = shift; my @elms = strptime($str); # Date::Parse will leave undefs if the elem cannot be found in the + string return 0 unless defined($elms[3]) && defined($elms[4]) && defined( +$elms[5]); my $str_r = sprintf("%4d-%02d-%02d", $elms[5]+1900, $elms[4]+1, $e +lms[3] ); # Run back trhough Date::Manip to make sure whatever we parsed is +a valid date return 0 unless Date::Manip::UnixDate($str_r,"%Y-%m-%d") eq $str_r +; return 1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found