0

I have a date object in Python and I want to convert it to datetime object with one simple step.

There is some not interesting solution like

datetime.datetime(my_date.year, my_date.month, my_date.day)

but I want a better way to solve this.

accdias
  • 5,160
  • 3
  • 19
  • 31
MMM
  • 29
  • 2
  • 10
  • 2
    Why not like this https://stackoverflow.com/questions/15661013/python-most-efficient-way-to-convert-date-to-datetime – sshashank124 Jan 05 '20 at 14:05
  • If you don't like the verbosity of your current solution, write a small function. Unfortunately there's not really a better way (see linked duplicate question). – Jonathon Reinhart Jan 05 '20 at 14:07
  • How are you acquiring this `datetime.date` object? Perhaps that code could be changed to return a `datetime.datetime` instead? – Jonathon Reinhart Jan 05 '20 at 14:08
  • Yeah, https://stackoverflow.com/questions/15661013/python-most-efficient-way-to-convert-date-to-datetime is the answer. Thanks @sshashank124 – MMM Jan 05 '20 at 14:26

0 Answers0