Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I have a date as "12-03-2014", I would like to convert it to:
"December 03, 2014".
I am getting an error like:
Error parsing time at /usr/lib64/perl5/Time/Piece.pm
Here is the code I am trying:
!/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $t = Time::Piece->new(); # Date 3 weeks from today's date my $future_date = $t + ONE_WEEK * 3; my $n_date = $future_date->mdy; my $converted_date = $t->strptime($n_date, '%B %d, $Y'); print " New Date = $n_date\n"; # December 03, 2014 print " Converted Date = $converted_date\n";
Thank you!

Replies are listed 'Best First'.
Re: Convert month number to month name
by choroba (Cardinal) on Nov 12, 2014 at 15:04 UTC
    You're almost there!
    1. You don't need to Parse a date, you need to Format it:
    2. You want to format the object, i.e. $future_date.
    my $converted_date = $t->strftime($future_date, '%B %d, %Y');

    Update: Fixed $Y -> %Y. Thanks toolic.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Convert month number to month name
by toolic (Bishop) on Nov 12, 2014 at 15:13 UTC
    Putting it all together, using choroba's advice, and fixing the format error (use %Y, not $Y):
    use warnings; use strict; use Time::Piece qw(); use Time::Seconds qw(ONE_WEEK); my $t = Time::Piece->new(); my $future_date = $t + ONE_WEEK * 3; my $converted_date = $future_date->strftime('%B %d, %Y'); print "Converted Date = $converted_date\n"; __END__ Converted Date = December 03, 2014
      Thank you, that explains, awesome!