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.
I would like to convert in perl the following date format:
"10 Feb 2009 19:13"
to the following:
"2009-02-10"
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The solution above is perfect but this works on my machine:
use Date::Format;
use Date::Parse;
print time2str("%Y-%m-%d", $time), "\n";
use Date::Format;
use Date::Parse;
print time2str("%Y-%m-%d", $time), "\n";
#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;
@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+).*#
print;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
use date::Format;
$string = "10 Feb 2009 19:13";
$time = str2time($string);
print time2str("%Y/%m/%d", time), "\n";