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: datetime.strptime raises error if date is before 1900
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: redrooster
Priority: normal Keywords:

Created on 2020-09-28 10:55 by redrooster, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg377592 - (view) Author: Red Rooster (redrooster) Date: 2020-09-28 10:55
This fails, because the date is before 1900:
d = datetime.strptime("28. Februar 1899", '%d. %B %Y')

But the opposite conversion direction works:
d=datetime(1899,2,28)
d.strftime('%d. %B %Y')

prints out "28. Februar 1899" as it should be.
msg377593 - (view) Author: Red Rooster (redrooster) Date: 2020-09-28 11:01
The issue is not that the date is before 1900, the issue are german month names. That strptime understands them, first set the locale like that:
locale.setlocale(locale.LC_TIME, "de_DE")
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86040
2020-09-28 11:01:55redroostersetstatus: open -> closed
resolution: not a bug
messages: + msg377593

stage: resolved
2020-09-28 10:55:46redroostercreate