[issue22058] datetime.datetime() should accept a datetime.date as init parameter

Alexander Belopolsky report at bugs.python.org
Thu Jul 24 20:29:29 CEST 2014


Alexander Belopolsky added the comment:

> some_datetime_object.date() is the obvious way to extract a
> date object from a datetime object.

Sorry if I was not clear enough about my use case.  I often have to deal with functions that are designed to take either date or datetime object as an argument, but only use date components.  In most cases this works automatically because datetime is a subclass of date.  However, there are some annoying exceptions.  For example, x > date(2001, 1, 1) will not work if x is a datetime instance.  If in this example I write x.date() > date(2001, 1, 1) - I get the opposite problem - it won't work when x is a date instance.

The "obvious" way would be date(x) > date(2001, 1, 1).

Can you suggest anything better than date(*x.timetuple()[:3]) > date(2001, 1, 1) here?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22058>
_______________________________________


More information about the Python-bugs-list mailing list