Use strftime
:
>>> from datetime import datetime
>>> datetime.today().strftime('%Y-%m-%d')
'2021-01-26'
To also include a zero-padded Hour:Minute:Second
at the end:
>>> datetime.today().strftime('%Y-%m-%d %H:%M:%S')
'2021-01-26 16:50:03'
More Related Contents:
- Calculate Time Difference Between Two Pandas Columns in Hours and Minutes
- How to make a timezone aware datetime object in Python?
- How to convert a UTC datetime to a local datetime using only standard library?
- Changing the formatting of a datetime axis in matplotlib
- How to make a timezone aware datetime object
- How do I round datetime column to nearest quarter hour
- How to print a date in a regular format?
- Convert DataFrame column type from string to datetime
- How to convert integer timestamp to Python datetime
- How to convert integer timestamp into a datetime
- How do you convert a time.struct_time object into a datetime object?
- In Python, how do you convert seconds since epoch to a `datetime` object?
- How do I create a datetime in Python from milliseconds?
- What’s the best way to find the inverse of datetime.isocalendar()?
- Inserting a Python datetime.datetime object into MySQL
- datetime from string in Python, best-guessing string format
- pandas to_datetime parsing wrong year
- Python/Pandas convert string to time only
- Convert Pandas Series to DateTime in a DataFrame
- Convert dataframe index to datetime
- How to convert a Date string to a DateTime object?
- Seaborn tsplot does not show datetimes on x axis well
- Group DataFrame in 5-minute intervals
- How to convert Python’s .isoformat() string back into datetime object [duplicate]
- Python summing up time
- Ceil a datetime to next quarter of an hour
- Clean way to convert quarterly periods to datetime in pandas
- Python: Matplotlib avoid plotting gaps
- pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working
- Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13