[Python-ideas] date.datetime() method to convert from date to datetime

Nick Coghlan ncoghlan at gmail.com
Fri Jun 3 06:45:25 CEST 2011


On Fri, Jun 3, 2011 at 2:07 PM, Evan Martin
<python-dev at realityexists.net> wrote:
> There is a datetime.date() method for converting from a datetime to a date,
> but no stdlib method to do the opposite conversion. Could a date.datetime()
> method be added that returns a datetime with the time component set to zero?
> Alternatively, if the object is already a datetime, it could simply return
> itself.
>
> This isn't exactly hard to do in user code, but the obvious way of doing it
> is a bit too verbose for such a simple operation. Less verbose ways are not
> obvious or are error-prone, as this StackOverflow question shows:
> http://stackoverflow.com/questions/1937622/convert-date-to-datetime-in-python

Alternatively, the second argument to datetime.combine() could be made
optional (defaulting to midnight).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list