Skip to Content
Menu
This question has been flagged
2 Replies
3747 Views

ValueError: : "unsupported operand type(s) for -: 'bool' and 'datetime.date'" while evaluating
"for record in self:\n  record['x_studio_number_of_days'] = record.x_studio_end_date - record.x_studio_start_date\n"
How can I fix this 
Avatar
Discard
Author Best Answer

I got it 

for record in self:

        if record.x_studio_end_date and record.x_studio_start_date:

                record['x_studio_number_of_days'] = (record.x_studio_end_date - record.x_studio_start_date).days


Avatar
Discard
Best Answer

Hi,

Seems one of the fields is coming as empty, thus you get this error. In order to overcome the error add if condition and make sure that both the field contains value before subtracting them.

for record in self:

        if record.x_studio_end_date and record.x_studio_start_date:

                record['x_studio_number_of_days'] = record.x_studio_end_date - record.x_studio_start_date


Thanks

Avatar
Discard
Author

I got error

ValueError: <class 'TypeError'>: "float() argument must be a string or a number, not 'datetime.timedelta'" while evaluating

"for record in self:\n if record.x_studio_end_date and record.x_studio_start_date:\n record['x_studio_number_of_days'] = record.x_studio_end_date - record.x_studio_start_date\n"