How do I convert a datetime to date?

StackOverflow

How do I convert a datetime.datetime object (e.g., the return value of datetime.datetime.now()) to a datetime.date object in Python?

Answer rating: 1247

Use the date() method:

datetime.datetime.now().date()

Answer rating: 149

From the documentation:

datetime.datetime.date()

Return date object with same year, month and day.





Get Solution for free from DataCamp guru