How do I convert datetime to date (in Python)?


Question

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

1
541
4/19/2018 6:45:13 AM

Accepted Answer

Use the date() method:

datetime.datetime.now().date()
821
1/28/2016 2:51:17 PM

From the documentation:

datetime.datetime.date()

Return date object with same year, month and day.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon