[New-bugs-announce] [issue40908] datetime strftime with %Y and 2 digit years
laurent chriqui
report at bugs.python.org
Mon Jun 8 06:00:33 EDT 2020
New submission from laurent chriqui <laurent at singlespot.com>:
When you use strftime with a 2 digit year i.e. '32' it outputs a '32' instead of '0032'.
This prevents parsing the string again with the same format through strftime.
Exemple:
import datetime
datetime_format="%Y"
date=datetime.date(32,1,1)
date_str=datetime.datetime.strftime(date, datetime_format)
datetime.datetime.strptime(date_str, datetime_format)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '32' does not match format '%Y'
----------
components: Library (Lib)
messages: 370971
nosy: laurent chriqui
priority: normal
severity: normal
status: open
title: datetime strftime with %Y and 2 digit years
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40908>
_______________________________________
More information about the New-bugs-announce
mailing list