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

Tim Peters report at bugs.python.org
Thu Jul 24 20:01:46 CEST 2014


Tim Peters added the comment:

Was the title of this meant to be

"datetime.date() should accept a datetime.datetime as init parameter"

instead?  That's what the example appears to be getting at.

If so, -1.  Datetime objects already have .date(), .time(), and .timetz() methods to extract, respectively, the date, naive time, and aware time portions of the datetime object.  In the other direction, the datetime .combine() constructor builds a datetime object out of date and time components.  As the docs say,

"For any datetime object d, d == datetime.combine(d.date(), d.timetz())"

Another way to spell this isn't needed.

> There is currently no obvious way to convert either date
> or datetime instance to date.

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

I don't know what it could mean to convert a date object to a date.  That's pretty much exactly like asking how to convert an int object to an int.  Huh? ;-)  date and int objects are immutable, so a need to make a copy (if that's what is meant) rarely arises.

----------
nosy: +tim.peters

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


More information about the Python-bugs-list mailing list