tags:

views:

93

answers:

2

I have current date as 1/10/2010 I need to convert it into 1 October 2010. Is there any module to convert?

+3  A: 

You can try:

my $date = '1/10/2010';
my @abbr = qw( dummy Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my($d,$m,$y) = split/\//g,$date;
my $new_date = $d.' '.$abbr[$m].' '.$y;
codaddict
+14  A: 

Use DateTime::Format::Strptime.

use DateTime::Format::Strptime;
my $Strp = DateTime::Format::Strptime->new(
                   pattern     => '%d/%m/%Y',
                   time_zone   => 'UTC',
                  );
my $dt = $Strp->parse_datetime('1/10/2010');
print $dt->strftime('%d %b %Y');

Edit: Thanks to @davorg for a hint with new.

eumiro
Please don't recommend indirect object notation. "Datetime::Format::Strptime->new(..)", not "new DateTime::Format::Strptime(...)". Indirect notation works most of the time. But when it doesn't, you'll waste hours tracking down the problem.
davorg
Better to use floating time zone than UTC. (Floating pretty much means "I don't care", while UTC is probably not the correct time zone for those dates.) The net result is the same.You can either pass "time_zone => 'Floating', or leave it out - it is the default.
mscha
thanks a lot .....it works
FRESHTER
Great. Do you accept the answer?
eumiro
thanks its working
FRESHTER