Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert dates to required format in Perl?

Tags:

perl

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

like image 331
Anil Avatar asked Nov 26 '25 15:11

Anil


1 Answers

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.

like image 139
eumiro Avatar answered Nov 29 '25 16:11

eumiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!