Working with dates requires to format the current date as YYYY-MM-DD. Python's datetime module makes this easy.

Here are three practical examples to get today's date in that format.

Example 1 — Basic datetime.date

Use the date class from the datetime module:

from datetime import date

today = date.today()
formatted = today.strftime("%Y-%m-%d")
print(formatted)

2026-01-26

What

  • date.today() returns the current date
  • strftime("%Y-%m-%d") formats it as YYYY-MM-DD

Example 2 — Full datetime.datetime Object

If you need time as well as date:

from datetime import datetime

now = datetime.now()
formatted = now.strftime("%Y-%m-%d")
print(formatted)

When

  • You want both date and time available
  • But only need the date string for output

Example 3 — Using datetime.date.isoformat()

Python also supports a built-in ISO format for dates:

from datetime import date

formatted = date.today().isoformat()
print(formatted)

Why

  • isoformat() directly returns "YYYY-MM-DD"
  • No need to specify a format string

Summary

Method Output Notes
date.today().strftime() YYYY-MM-DD Standard and flexible
datetime.now().strftime() YYYY-MM-DD Good if time needed too
date.today().isoformat() YYYY-MM-DD Shortest and cleanest