Borislav Hadzhiev
Wed Apr 20 2022·2 min read
Photo by Andrew Svk
The Python "TypeError: descriptor 'date' for 'datetime.datetime' objects
doesn't apply to a 'int' object" occurs when we incorrectly try to use the
date
class. 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.
The date
class is directly available in the datetime
module.
import datetime d = datetime.date(2025, 11, 21) print(d) # 👉️ 2025-11-21
The
datetime.date
class takes the year
, month
and day
as arguments.
Note that all arguments are required and must be in the following ranges:
MINYEAR
<= year <= MAXYEAR
If an argument is outside the specified ranges, a ValueError
is raised.
You can also import the date
class from the datetime
module.
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 date
class.
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 datetime
module are being used in the file.It is also quite confusing that there is a datetime
class in the datetime
module.
If you decide to directly import the date
class from the datetime
module,
make sure to not declare a date
variable in your code as that would override
the date
class.