7

I have a Date object and want to easily convert it to DateTime object, setting the time to an arbitrary value (e.g. 12:00:00).

I know it is possible taking the string and fiddleing with strptime and strftime.

I am curious if there is a easier, direct way to do that.

rollinger
  • 531
  • 1
  • 4
  • 15
  • 1
    Django is just a python web framework, so this may be what you are looking for http://stackoverflow.com/questions/1937622/convert-date-to-datetime-in-python – JensB May 13 '14 at 12:32
  • 1
    See [Convert date to datetime in Python](http://stackoverflow.com/a/1937636/3096768). Don't forget that Django is just Python! – pcoronel May 13 '14 at 12:32
  • Does this answer your question? [Convert date to datetime in Python](https://stackoverflow.com/questions/1937622/convert-date-to-datetime-in-python) – cellepo Nov 24 '20 at 20:46

1 Answers1

15

It can be done using datetime.combine(date, time), like suggested in: https://stackoverflow.com/a/1937636/3199774

from datetime import date
from datetime import datetime
d = date.today()
datetime.combine(d, datetime.min.time())
Community
  • 1
  • 1
tsaarni
  • 186
  • 1
  • 4