in reply to Re^2: Question on date formatting
in thread Question on date formatting

Example:
my @data = ( "blah blah 6/20/2000 4:56 foo bar baz\n", "bling blang 20.6.2000 4:56 flzb gzrk\n" ); for my $string ( @data ) { $string =~ s{ (\d{1,2}) ([./]) (\d{1,2}) \2 (\d{4}) \s+ (\d{1,2}):(\d{2}) } { my @a=($2 eq ".") ? ($4,$3,$1) : ($4,$1,$3); sprintf( "%s-%02d-%02d %02d:%s", @a,$5,$6 ) }ex; print $string; }
That is, whatever string variable happens to contain one of the two types of date format, apply the lengthy "s{}{}" substitution statement to that string.

UPDATE: Forgot to mention: if you have a string with more than one date in it (e.g. "from 1/2/2000 to 3/4/2000"), just change the "ex" at the end to "exg".