How to check if date is valid in perl?

My date format is dd/mm/yyyy

This date should return an error:  30/31/2009

How can I check this date and return that it does not exist.
dmalovichAsked:
Who is Participating?
 
farzanjConnect With a Mentor Commented:
That is a date in YYYYMMDD format.  
You can get it like

my $date = '30/31/2009';
my ($dd, $mm, $yyyy) = $date =~ m{(\d\d)/(\d\d)/(\d\d\d\d)};

my $yyyymmdd = "$yyyy$mm$dd";

You can also write test conditions yourself as well
0
 
farzanjCommented:
Try
use DateTime::Format::ISO8601;
eval {
    $date = DateTime::Format::ISO8601->parse_datetime("20061730");
};
if ( $@ ) { print "ERROR: date not valid" };

Open in new window

0
 
dmalovichAuthor Commented:
What does "20061730" represent?
0
 
dmalovichAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.