Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
3738 Tampilan

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
Buang
Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Penulis

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"