Question

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.

Was it helpful?

Solution

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())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top