[New-bugs-announce] [issue44610] Format issue with strftime and %Y

Bartosz Kaznowski report at bugs.python.org
Mon Jul 12 11:23:50 EDT 2021


New submission from Bartosz Kaznowski <bartekkaznowski at gmail.com>:

When you convert a date pre the year 1000 to a string with `%Y` as the formatter and then back to a date again then it fails. This is because `%Y` expects it to be formatted with leading zeroes. For example, the year 1/01/01 (yyyy/mm/dd) should be 0001/01/01 when formatting using %Y/%m/%d. However, %Y returns 1.
You can see this in action here:

from datetime import date, datetime
format = "%Y-%m-%d"
formatted = date.min.strftime("%Y-%m-%d")
datetime.strptime(formatted, format).date()

`ValueError: time data '1-01-01' does not match format '%Y-%m-%d'` is raised on the forth line.

----------
components: Library (Lib)
messages: 397329
nosy: bkaznowski
priority: normal
severity: normal
status: open
title: Format issue with strftime and %Y
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44610>
_______________________________________


More information about the New-bugs-announce mailing list