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.datetime.min.strftime('%Y') not working
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: datetime.strftime dislikes years before 1900
View: 1777412
Assigned To: Nosy List: filip.zyzniewski, krzaq, r.david.murray
Priority: normal Keywords:

Created on 2013-10-04 11:00 by filip.zyzniewski, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg198941 - (view) Author: Filip Zyzniewski (filip.zyzniewski) Date: 2013-10-04 11:00
The datetime class provides a min datetime object which is not formattable:

on Python 2:

$ python
Python 2.7.3 (default, Apr 10 2013, 05:13:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.min.strftime('%Y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: year=1 is before 1900; the datetime strftime() methods require year >= 1900
>>> 

and on Python 3:

$ python3
Python 3.2.3 (default, Apr 10 2013, 05:07:54) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.min.strftime('%Y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: year=1 is before 1000; the datetime strftime() methods require year >= 1000
>>>

It seems to me that either datetime.datetime.min.year should be increased to 1900/1000 or strftime should be able to format year=1 - it is strange that the API doesn't support its own constants.
msg198944 - (view) Author: Tomasz Zaleski (krzaq) Date: 2013-10-04 11:52
works correctly on python3.3:
Python 3.3.2 (default, Oct  4 2013, 12:21:07)
[GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.min.strftime('%Y')
'0001'

issue on 2.7:
Python 2.7.5 (default, Sep 17 2013, 12:11:31)
[GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.min.strftime('%Y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: year=1 is before 1900; the datetime strftime() methods require year >= 1900
msg198951 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-10-04 14:02
Indeed, this is already fixed.  This issue is a duplicate of issue 1777412.  The bug will not be fixed in earlier versions for the reasons discussed in that issue.
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63361
2013-10-04 14:02:48r.david.murraysetstatus: open -> closed

superseder: datetime.strftime dislikes years before 1900

nosy: + r.david.murray
messages: + msg198951
resolution: duplicate
stage: resolved
2013-10-04 11:52:02krzaqsetnosy: + krzaq
messages: + msg198944
2013-10-04 11:00:07filip.zyzniewskicreate