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 <rep...@bugs.python.org>
<http://bugs.python.org/issue22058>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to