The Python "TypeError: descriptor 'date' for 'datetime.datetime' objects
doesn't apply to a 'int' object" occurs when we incorrectly try to use the
To solve the error import the
datetime module and use the class as
datetime.date(2025, 11, 24).
Here is an example of how the error occurs.
import datetime # ⛔️ TypeError: descriptor 'date' for 'datetime.datetime' objects doesn't apply to a 'int' object d = datetime.datetime.date(2025, 11, 21)
We incorrectly used the
date class in the example.
date class is directly available in the
import datetime d = datetime.date(2025, 11, 21) print(d) # 👉️ 2025-11-21
class takes the
day as arguments.
Note that all arguments are required and must be in the following ranges:
MINYEAR<= year <=
If an argument is outside the specified ranges, a
ValueError is raised.
dateclass from the
You can also import the
date class from the
from datetime import date d = date(2025, 11, 21) print(d) # 👉️ 2025-11-21
Instead of importing the entire
datetime module, we imported only the
This should be your preferred approach because it makes your code easier to read.
import datetime, it is much harder to see which classes or methods from the
datetimemodule are being used in the file.
It is also quite confusing that there is a
datetime class in the
import datetime # 👇️ <module 'datetime' from '/usr/lib/python3.11/datetime.py'> print(datetime) # 👇️ <class 'datetime.datetime'> print(datetime.datetime) # 👇️ <class 'datetime.date'> print(datetime.date)
The first print() call prints the
The next two calls print the
A module is a collection of classes and methods.
If you need to specify the hours, minutes and seconds, use the
from datetime import datetime d = datetime(2024, 11, 24, 9, 30, 0) print(d) # 👉️ 2024-11-24 09:30:00
If you decide to directly import the
date class from the
make sure to not declare a
date variable in your code as that would override
You can learn more about the related topics by checking out the following tutorials: