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.


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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap