On Wed, Jul 24, 2013 at 10:56 PM, Michael Brader <mbra...@internode.com.au>wrote:
> > On 07/25/2013 10:14 AM, mimic...@gmail.com wrote: > > I was trying to use Date::Simple to convert date from DD-MM-YYYY to ISO > standard YYYY-MM-DD, but it produced error below because it returned undef > when the date passed is not ISO standard. > > > Yeah on quick scan of the perldoc it looks like Date::Simple doesn't offer > much in the way of parsing. > > [...] > > Most of the date modules on CPAN cannot do the job for me. I spent time > reading documentations but as it now stands, I have to do this myself. > > > There are at least 2 modules that can definitely do the job for you, > Date::Manip::Date and DateTime (with DateTime::Format::Natural). I usually > use the latter, but since you want the former: > > Have a look at the documentation for Date::Manip::Date and look for > parse_format and printf > > > Date::Manip and friends are wonderfully versatile but with even in this simple case, it does start to get a bit twisty with special parse and output methods: use Date::Manip::Date; my $date = Date::Manip::Date->new; my $err=$date->parse_format("%d-%m-%Y","29-01-1972") or die "can't parse date: $err"; print $date->printf("%m-%d-%Y"); # 01-29-1972 P.S. IMO, it'd be superb if the earlier functional interface or even parse_date in Date::Manip::Date would just accept a hash ref of non-standard format specs. Then, you could just output with UnixDate as usual. eg, ParseDate( ... , { fmt1="%d-%m-%Y", fmt2=... } ); -- Charles DeRykus