Link to home
Start Free TrialLog in
Avatar of Purdue_Pete
Purdue_Pete

asked on

Date Format Conversion

Hi,
I would like to convert in perl the following date format:
"10 Feb 2009 19:13"

to the following:
"2009-02-10"

Thank you.
Avatar of SimonHowald
SimonHowald

#!/usr/bin/perl

use date::Format;

$string = "10 Feb 2009 19:13";
$time = str2time($string);
print time2str("%Y/%m/%d", time), "\n";
ASKER CERTIFIED SOLUTION
Avatar of SimonHowald
SimonHowald

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The solution above is perfect but this works on my machine:

use Date::Format;
use Date::Parse;

print time2str("%Y-%m-%d", $time), "\n";
Avatar of ozo
#If you want to do it wthout modules
@mon{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = ('01'..'12');
$_ = "10 Feb 2009 19:13";
s#(\d+)\s*(\w+)\s*(\d+).*#$3-$mon{$2}-$1#;
print;
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
With modules you can convert dates in different formats, e.g.

22 Feb 09 7:30:44
23/Feb/09 7:30:44
13-Feb-08 7:30:44
Jan 25 09 7:30

with or without hours, minutes and seconds