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: date-datetime comparison doesn't work
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: collinwinter, jribbens, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2007-03-04 11:51 by jribbens, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31417 - (view) Author: Jon Ribbens (jribbens) * Date: 2007-03-04 11:51
Summary: bug #1028306 was not a bug, but the fix for it introduced one

Comparing a date to a datetime currently throws an exception. This makes no sense. In what way is:

  datetime(2006, 1, 1, 0, 0, 0) < date(2007, 1, 1)

not a perfectly reasonable and well-defined comparison? Throwing an exception here violates the "Principle of Least Surprise" to a considerable degree.

Obviously some slight ambiguity arises if the date and the datetime differ only in the time part. There are two sensible responses in this situation that I can see:

  Treat dates as if they have a time-part of midnight. This is my preferred solution, and it is already what the datetime module does, for example, when subtracting two dates.

  Treat dates as if they refer to the entire day, i.e. if the date and datetime differ only in the time part then they are equal. This is consistent but becomes confusing in other situations such as when subtracting dates.
msg31418 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-08 20:55
I think this warrants discussion on python-dev (http://mail.python.org/mailman/listinfo/python-dev) as to which of the two date interpretations to pick. Please post a description of the problem there and ask for suggestions.
msg31419 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-03-08 21:09
Tim, any thoughts?
msg31420 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-19 17:22
Quoting from http://mail.python.org/pipermail/python-ideas/2007-March/000331.html: """refusing to compare dates and datetimes is the right thing to do""". Closing.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44654
2007-03-04 11:51:23jribbenscreate