278

I have two objects that represent the same event instance --- one holds the date, the other the time of this event, and I want to create a datetime object.

Since one can't simply add date and time objects (following call fails):

 datetime.date(2011, 01, 01) + datetime.time(10, 23)
Demis
  • 5,278
  • 4
  • 23
  • 34
jb.
  • 23,300
  • 18
  • 98
  • 136
  • See [What is the standard way to add N seconds to datetime.time in Python?](https://stackoverflow.com/q/100210/562769) – Martin Thoma Dec 07 '17 at 07:26

1 Answers1

466

It's in the python docs.

import datetime
datetime.datetime.combine(datetime.date(2011, 1, 1), 
                          datetime.time(10, 23))

returns

datetime.datetime(2011, 1, 1, 10, 23)
Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
eumiro
  • 207,213
  • 34
  • 299
  • 261