http://www.perlmonks.org?node_id=1231677

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

I'm finding something of an inconsistent behaviour when using DateTime::Format::Strptime.

The program as shown below illustrates the problem... but in short, the parsing of an 'hh:mm:ss p' format on a 12-hour clock doesn't seem to work with a 'PM' included in the string. Using a 24-hour clock format (and no 'PM') seems to work Ok... but my data isn't presented in that format.

An example program:-

use strict; use warnings; #use diagnostics; use DateTime; use DateTime::Format::Strptime; our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); my $dtnow = DateTime->now(time_zone => $LocalTZ); # Current *local* + time printf("\$dtnow: !%s!\n", $dtnow); my $lo = "18/03/2019 10:12:53 am"; # Always works my $hi = "24/03/2019 3:15:00 pm"; # Does not work... the format I + need to use # my $hi = "24/03/2019 03:15:00 pm"; # Does not work # my $hi = "24/03/2019 3:15:00 pm"; # Does not work # my $hi = "24/03/2019 15:15:00 pm"; # Works but 15hrs with 'pm' i +s silly # my $hi = "24/03/2019 15:15:00"; # Works my $dmy_fmt = DateTime::Format::Strptime->new( # Let DateTime use 'dd +/mm/yyyy' pattern => '%d/%m/%Y %H:%M:%S %p', # pattern => '%d/%m/%Y %H:%M:%S', # Use this when no 'am/pm' + in the date string time_zone => 'Australia/Victoria', # time_zone => 'local', ); my $lodt = $dmy_fmt->parse_datetime($lo); printf(" \$lodt: !%s!\n", $lodt); my $hidt = $dmy_fmt->parse_datetime($hi); printf(" \$hidt: !%s!\n", $hidt);

I have updated the modules to the latest versions via CPAN... but it doesn't make any difference. Otherwise, I'm talking about ActiveState Perl v5.16.3 Build 1603, running under Windows 10 64-bit.

Any clues on what's wrong here... with what I'm trying to do OR with the ways the functions are working?

Thanks a heap for any forthcoming suggestions.