Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to calculate difference between two dates

By
Atul Kumar jain
on 3/18/14, 5:05 AM 2,030 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'),

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

Atul Kumar jain
on 3/18/14, 7:56 AM
1

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 3/18/14, 8:05 AM

Hi,

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

0
sarkar
On 4/8/16, 3:49 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/18/14, 5:05 AM
Seen: 2030 times
Last updated: 4/8/16, 3:49 AM