Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 208
morpheous Avatar asked Jul 07 '10 13:07

morpheous


2 Answers

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

like image 83
Ignacio Vazquez-Abrams Avatar answered Nov 09 '22 09:11

Ignacio Vazquez-Abrams


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

Remove method call and be happy.

like image 32
Alexander Artemenko Avatar answered Nov 09 '22 09:11

Alexander Artemenko