Skip to Content
मेन्यू
This question has been flagged
3 Replies
11994 Views

In My custom module i am unable to calculate difference between two dates

my field is

'date_s':fields.datetime('Start Date'),
'date_e':fields.datetime('End Date'),

I want to calculate difference automatically in my duration field

 'Duration':fields.char('Duration'),
Avatar
Discard
Author

i correct my function but still i got error like this data_string[found.end():]) ValueError: unconverted data remains: 10:52:57 and my function is def _get_days(self, cr, uid, ids, field_name, args, context=None): res = {} for date in self.browse(cr, uid, ids, context=context): fmt = '%Y-%m-%d' date.date_s = datetime.strptime(date.date_s, fmt) date.date_e = datetime.strptime(date.date_e, fmt) res[date.id] = ((date.date_s-date.date_e).days) or False return res

Best Answer

Hi,

You may refer the following link: https://accounts.openerp.com/forum/Help-1/question/31486

Avatar
Discard
Best Answer

Hello,

d_frm_obj = datetime.datetime.strptime(date_s, DEFAULT_SERVER_DATETIME_FORMAT)

d_to_obj = datetime.datetime.strptime(date_e, DEFAULT_SERVER_DATETIME_FORMAT)


duration = d_to_obj - d_frm_obj

try this

Avatar
Discard