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.
Purdue_PeteAsked:
Who is Participating?
 
SimonHowaldConnect With a Mentor Commented:
typo:please read below
print time2str("%Y/%m/%d", time), "\n";
to
print time2str("%Y/%m/%d", $time), "\n";
0
 
SimonHowaldCommented:
#!/usr/bin/perl

use date::Format;

$string = "10 Feb 2009 19:13";
$time = str2time($string);
print time2str("%Y/%m/%d", time), "\n";
0
 
Fero45Commented:
The solution above is perfect but this works on my machine:

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

print time2str("%Y-%m-%d", $time), "\n";
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
ozoCommented:
#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;
0
 
IceCrackConnect With a Mentor Commented:
($day, $month, $year, $time) = split(/\s/, $currentdate);
$date = join('-', $year,$month,$day);

0
 
Fero45Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.