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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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