Skip to Content
मेन्यू
This question has been flagged
1 Reply
5076 Views

How to subtract date now and birthday field then pass the age value in a field (readonly)?

Avatar
Discard
Best Answer

Hi Kasai,

You can calculate age using the following script:-

            start = datetime.strptime(object.birthdate, DEFAULT_SERVER_DATE_FORMAT)
            end = datetime.strptime(time.strftime(DEFAULT_SERVER_DATE_FORMAT), DEFAULT_SERVER_DATE_FORMAT)
            delta = end - start
            age = (delta.days / 365)

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,, please let me know if it does.

Avatar
Discard
Related Posts Replies Views Activity
1
मार्च 22
3557
1
मई 22
2356
3
अक्तू॰ 15
4341
3
जून 25
1648
1
जन॰ 25
18344