Reputation: 363
I am trying to convert date from yymmdd
to YYYY-MM-DD
with Time::Piece module. With the input as Nov 31, 2000 (20001131)
, I am getting output as 2000-12-01
. In reality, Nov 31
doesn't even exists.
use Time::Piece;
my $dt_str = Time::Piece->strptime('20001131', '%Y%m%d')->strftime('%Y-%m-%d');
print $dt_str;
Am I missing something here?
Upvotes: 3
Views: 155
Reputation: 98388
Internally, it does only rough validation and error reporting, and then performs the same transformations as POSIX::mktime does; any days beyond the end of a month will just cause it to advance the produced date into the next month. This does seem a little inconsistent; since it allows that for days, I'd also expect it to treat '20005931' as '2004-12-01', but instead it errors out.
Upvotes: 1