morpheous
morpheous

Reputation: 17006

AttributeError: 'datetime.date' object has no 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 the error:

AttributeError: 'datetime.date' object has no attribute 'date'

How to fix this?

Upvotes: 18

Views: 65560

Answers (2)

Alexander Artemenko
Alexander Artemenko

Reputation: 22836

.date() method exists only on datetime.datetime objects. You have object of datetime.date type.

Remove method call and be happy.

Upvotes: 9

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

Stop trying to call the date() method of a date object. It's already a date.

Upvotes: 36

Related Questions