AttributeError: object 'datetime.date' does not have attribute 'date'

I have a script like this:

import datetime # variable cal_start_of_week_date has type <type 'datetime.date'> # variable period has type <type 'datetime.timedelta'> cal_prev_monday = (cal_start_of_week_date - period).date() 

When the above statement is executed, I get an error message:

AttributeError: object 'datetime.date' does not have attribute 'date'

How to fix it?

+4
source share
2 answers

Stop trying to call the date() method of the date() object. This is already a date .

+18
source

.date () exists only for datetime.datetime objects. You have an object of type datetime.date.

Remove the method call and be happy.

+5
source

Source: https://habr.com/ru/post/1314954/


All Articles