How do I convert a datetime to date? How do I convert a datetime to date? python python

How do I convert a datetime to date?


Use the date() method:

datetime.datetime.now().date()


From the documentation:

datetime.datetime.date()

Return date object with same year, month and day.


You use the datetime.datetime.date() method:

datetime.datetime.now().date()

Obviously, the expression above can (and should IMHO :) be written as:

datetime.date.today()


matomo