Hi everybody !!!!
Please i have twi fields date and i want to compare them. How can i doo it please help please
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi everybody !!!!
Please i have twi fields date and i want to compare them. How can i doo it please help please
Hi,
You can compare date by:- ( here lets assume that i assigned dates field to "start_date" and "end_date")
start = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT)
end = datetime.strptime(end_date, DEFAULT_SERVER_DATE_FORMAT)
delta = end - start
num_of_days= delta.days
Then you can use delta.days to get number of days
Please don't forget to import following:-
import time
from dateutil.relativedelta import relativedelta
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
Hope this helps...
Thanks guys for your answers but both of them don't work.
what is object.birthdate because it shows me an error AttributeError: type object 'object' has no attribute 'birthdate'
Please help guys
Hi Abdelwahed, can you check now? I updated the Answer. Hope it helps.. let me know if any probs..
Try like below code , im not sure ..it may helps..
also add this in xml file
class hr_contract(osv.Model):
_inherit='hr.contract'
_columns={
'date1':fields.date('Date'),
'date2':fields.date('Date2')
'days':fields.function(_get_days, string="Sub Model", type='char', store=True)
}
def _get_days(self, cr, uid, ids, field_name, arg, context=None):*
res = {}
for val in self.browse(cr, uid, ids, context):
start_day= datetime.strptime(val.date1 ,DEFAULT_SERVER_DATE_FORMAT)
end_day=datetime.strptime(time.strftime(DEFAULT_SERVER_DATE_FORMAT), DEFAULT_SERVER_DATE_FORMAT)
delta = (end - start ).days
return delta
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
4
thg 10 16
|
31720 | ||
|
1
thg 9 15
|
4364 | ||
|
1
thg 6 15
|
1257 | ||
|
0
thg 4 15
|
973 | ||
|
2
thg 4 15
|
1268 |
Thanks a lot for your help :) But what i want to compare is the two fields in hr.contract which are date how can i convert them to datetime if i am going to use them ??
Hi, In my answer both start and end are date fields....