Python: Get Todays date in yyyy-MM-dd format

In order to get today's date in yyyy-MM-dd format in Python we can make use of the datetime module.

datetime module contains classes for manipulating dates and times.


Example 1:
from datetime import date

todays_date_yyyy_MM_dd = str(date.today())

print(todays_date_yyyy_MM_dd)
Output:
2023-07-6

date.today() returns the current date in local timezone.

Must Read Documentations:

1. https://docs.python.org/3/library/datetime.html#datetime.date.today

2. https://docs.python.org/3/library/datetime.html

3. https://docs.python.org/3/library/datetime.html#datetime.timezone.utc


As yyyy-MM-dd is the ISO standard format for date, you can also make use of the date.isoformat() function which will return a string representing the date in ISO 8601.


Example 2:
from datetime import date

todays_date_iso_format = date.today().isoformat()

print(todays_date_iso_format)
Output:
2023-07-6
Python- Get Todays date in yyyy-MM-dd ISO format

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!