-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
strftime
does not always return the date in the expected format
#111817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe the bug is not in |
Docs clearly state that it should be https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes And it works correctly for 3.13: Python 3.13.0a1+ (heads/issue-111495-dirty:340d25676be, Nov 5 2023, 14:21:42) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.date(22, 11, 11).strftime("%Y-%m-%d")
'0022-11-11' and for 3.11.5: Python 3.11.5 (main, Sep 5 2023, 10:34:31) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.date(22, 11, 11).strftime("%Y-%m-%d")
'0022-11-11' |
This is a glibc issue. @sobolevn showed that Darwin (macOS) is unaffected, here's Windows:
FreeBSD:
musl:
And finally, glibc:
See also gh-57514, gh-88776, and probably others. Closing as duplicate of gh-57514. |
Bug report
Bug description:
When using
%Y
in the format I would expect that the year in the return value has a length of four digits.When converting the string back to a date using
strptime()
with the format%Y-%m-%d
it does crash because it expects the string to have four digits.CPython versions tested on:
3.11
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: