Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Date to Datetime

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.

like image 410
rollinger Avatar asked Dec 12 '22 05:12

rollinger


1 Answers

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())
like image 67
tsaarni Avatar answered Dec 22 '22 17:12

tsaarni