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

Hello,

I have a problem using the package DateTime::Format::Strptime.

Using the two following patterns :

pattern => '%B %d %Y %H:%M:%S' eg. 'Dec 16 2014 21:03:46'

pattern => '%B %d %H:%M:%S' eg. 'Sep 16 21:00:00'

The first pattern works, but not the second (which does not include the year neither in pattern neither in string).

Where could be the problem ?

#!/usr/bin/perl use DateTime::Format::Strptime; my $t = 'Dec 16 2014 21:03:46'; my $Strp = DateTime::Format::Strptime::->new( pattern => '%B %d %Y %H:%M:%S', locale => 'en_US', ); # my $dt = $Strp->parse_datetime($t); print "'$dt'\n"; my $t2 = 'Sep 16 21:00:00'; my $Strp2 = DateTime::Format::Strptime::->new( pattern => '%B %d %H:%M:%S', locale => 'eu_US', ); # my $dt2 = $Strp2->parse_datetime($t2); print "'$dt2'\n";
Output is :
'2014-12-16T21:03:46' ''

Replies are listed 'Best First'.
Re: about DateTime::Format::Strptime
by toolic (Bishop) on Dec 16, 2014 at 21:09 UTC
    From the DateTime::Format::Strptime SYNOPSIS: on_error
    use warnings; use strict; use DateTime::Format::Strptime; my $t2 = 'Sep 16 21:00:00'; my $Strp2 = DateTime::Format::Strptime->new( pattern => '%B %d %H:%M:%S', locale => 'en_US', on_error => 'croak', ); my $dt2 = $Strp2->parse_datetime($t2); print "'$dt2'\n"; __END__ There is no use providing a month name (Sep) without providing a year.
Re: about DateTime::Format::Strptime
by MidLifeXis (Monsignor) on Dec 16, 2014 at 21:10 UTC

    Line 20:      locale => 'eu_US',

    I think you mean en_US

    --MidLifeXis

      The problem is resolved

      Simply a date variable without a specific year can not be created.