Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: checking for valid date

by Ieronim (Friar)
on Jul 30, 2006 at 10:31 UTC ( #564603=note: print w/replies, xml ) Need Help??

in reply to checking for valid date

The standard module Time::Local will do the trick.
use Time::Local; my $date = ' 19990230'; # 30th Feb 1999 $date =~ s/\s+$//; $date =~ s/^\s*//; my ($year, $month, $day) = unpack "A4 A2 A2", $date; eval{ timelocal(0,0,0,$day, $month-1, $year); # dies in case of bad date + 1; } or print "Bad date: $@";
UPD: But this won't work for valid dates less than Jan 1 1970 and greater than Jan 19 2038. If you need to check dates outside this range, try Date::Manip.

     s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://564603]
shmem puts down the Canon garments and dresses as Chancellor
[vrk]: Congratulations. You should have Cookies
[shmem]: thanks vrk - but I'll rather have a plate of "silly con charme"
Lady_Aleena is trying to explain perl regexen to people right now and explaining how variables expand in regexen.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-04-28 09:37 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (520 votes). Check out past polls.