The today method of the datetime module

The today method of the datetime module returns the current date. We do not specify anything in the first method.

Syntax

pythonimport datetime

datetime.date.today()

Example

Let's find out the current date:

pythonimport datetime

res = datetime.date.today()
print(res)

The result of the executed code:

python'2025-12-31'

Example

Now let's derive the day, month and year separately from our current date:

pythonimport datetime

res = datetime.date.today()
print(res.day)
print(res.month)
print(res.year)

The result of the executed code:

python31
12
2025

See also

  • method datetime of module datetime,
    which creates a date and time object
  • method strftime of module datetime,
    which creates a formatted string with date and time
  • method now of module datetime,
    which returns the current time
  • method date of module datetime,
    which creates a new object with a date
  • method isleap of the calendar module,
    which determines a leap year