jai_dgl has asked for the wisdom of the Perl Monks concerning the following question:

How do I extract date and time from a text content and convert it into a standard format. Example 1. Today's date is June 12 , 2008 I need to extract the date Example 2. Today's date is 12/06/08, how do I extract date from this ------------------------------------------------------------ I need to extract date from the both as well as any other format also.

Replies are listed 'Best First'.
Re: Extract date and time
by Erez (Priest) on Jun 12, 2008 at 06:39 UTC
Re: Extract date and time
by pc88mxer (Vicar) on Jun 12, 2008 at 06:53 UTC
    Here's a solution using Date::Parse:
    use Date::Parse; while (<>) { chomp; my @t = strptime($_); my $d = sprintf("%d/%d/%d", $t[3], $t[4]+1, $t[5]+1900); print "$_ -> $d\n"; } __END__ June 12, 2008 -> 12/6/2008

    Some caveats: Date::Parse only recognizes English month names and follows American conventions for things like 12/6/08 which parses as December 6th, 2008. Otherwise it will recognize most variations of specifying dates, e.g. (12 Jun 2008, 2008-06-12, etc.)