Home > Software design >  Removing the time from datetime output (Python)
Removing the time from datetime output (Python)

Time:05-13

Remove the time from this code.

Current Code:

from datetime import datetime, timedelta
    
date = datetime.today() - timedelta(days=1)

print("Today's date:", date)

Output:

Today's date: 2022-05-11 18:44:01.832558

Desired Output:

Today's date: 2022-05-11

CodePudding user response:

Your date value is actually a datetime object. Call date() on it to convert it to just a date:

>>> import datetime
>>> print(datetime.datetime.today().date())
2022-05-12
  • Related