0 votes
1 view
in Python by (47.8k points)

Is there a built-in method for converting a date to a datetime in Python, for example getting the datetime for the midnight of the given date? The opposite conversion is easy: datetime has a .date() method.

Do I really have to manually call datetime(d.year, d.month, d.day)?

1 Answer

0 votes
by (107k points)

To convert date to datetime in Python you can use datetime.combine(date, time) following is the code that explains how to do it:-

from datetime import date

from datetime import datetime

dt = datetime.combine(date.today(), datetime.min.time())



Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !