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
2010-09-21 10:02:06
+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
2010-09-21 10:03:18
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
2010-09-21 10:38:09
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
2010-09-21 11:07:42
thanks a lot .....it works
FRESHTER
2010-09-21 13:23:31
Great. Do you accept the answer?
eumiro
2010-09-21 15:01:35
thanks its working
FRESHTER
2010-09-29 09:38:35