This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inconsistent behaviour in strftime
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, josh.r, ned.deily, p-ganssle, valdemarrolfsen
Priority: normal Keywords:

Created on 2020-09-03 11:45 by valdemarrolfsen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg376296 - (view) Author: Valdemar Rolfsen (valdemarrolfsen) Date: 2020-09-03 11:45
Inconsistency in strftime between python 3.6 and 3.7 when parsing first-century dates.

Python 3.6
>>> datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")
'0020-10-05'

Python 3.7
>>> datetime.datetime.strptime("0020-10-05", "%Y-%m-%d").strftime("%Y-%m-%d")
'20-10-05'

This means that the following would work for 3.6 but raise a ValueError for 3.7:

>>> d = "0020-10-05"
>>> d = datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")
>>> d = datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")
msg376313 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2020-09-03 19:37
3.8.2 (on Alpine Linux under WSL) produces '0020-10-05', just like your 3.6 example. Not seeing anything obvious in commit history that would break it for 3.7. That said, 3.7 is in security fix only mode at this point (see https://devguide.python.org/#status-of-python-branches ); as this works on the latest release, I'm thinking this won't be fixed for 3.7.
msg376540 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-09-08 00:08
The behavior you see with a Python 3.7 is not universal. For example, on macOS:

Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime("0020-10-05", "%Y-%m-%d").strftime("%Y-%m-%d")
'0020-10-05'

So there is apparently something different in the environments between the Python 3.6 and 3.7 you are using, rather than an issue in Python itself. Perhaps a comparison of the outputs between:

python3.6 -m test.pythoninfo
python3.7 -m test.pythoninfo

will suggest something. In any case, as Josh notes, Python 3.7 is in the security-fix-only phase of its life cycle so even if there were an issue in Python itself it would likely not meet the criteria to be fixed in 3.7.
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85868
2021-12-10 09:51:56iritkatrielsetstatus: pending -> closed
stage: resolved
2020-09-08 00:08:26ned.deilysetstatus: open -> pending

nosy: + ned.deily
messages: + msg376540

resolution: works for me
2020-09-03 19:37:04josh.rsetnosy: + josh.r

messages: + msg376313
title: Inconcistent behaviour in strftime -> Inconsistent behaviour in strftime
2020-09-03 11:45:52valdemarrolfsencreate