python – How do I convert a datetime to date?

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.

python – How do I convert a datetime to date?

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()

Leave a Reply

Your email address will not be published. Required fields are marked *