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
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
RegistrierenVerknüpfte Beiträge | Antworten | Ansichten | Aktivität | |
---|---|---|---|---|
|
4
Okt. 16
|
31716 | ||
|
1
Sept. 15
|
4346 | ||
|
1
Juni 15
|
1248 | ||
|
0
Apr. 15
|
970 | ||
|
2
Apr. 15
|
1260 |
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....