in reply to Parsing oddball dates
I had a similar problem reading dates from a text file in order to report on projected developer headcount, and here's what worked for me
use Date::Manip; # For ParseDate()'s ability to # handle non-ISO date formats # like "today" use Date::Calc qw (Decode_Date_EU); # For Decode_Date_EU()'s ability # to handle extra bits that # ParseDate() doesn't use Date::Simple qw (today); # For convenience, and for # compatibility with Date::Range sub DateSimple { # Try hard to turn a string into Date::Simple my $workdate = shift; # First try ParseDate my $date=UnixDate(ParseDate($workdate),"%Y-%m-%d"); # If that didn't work then give Decode_Date_EU a try unless ($date) { $workdate =~ s/(\d)[a-z]{2}/$1/ig; # Remove number suffixes if (my ($year,$month,$day) = Decode_Date_EU($workdate)) { $date = sprintf("%04i-%02i-%02i",$year,$month,$day); } } $date ? Date::Simple->new($date) : undef; }
|
|---|