Odoo Help

0

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

By
Ken Kasai
on 1/29/15, 11:12 AM 972 views

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

3

Baiju KS

--Baiju KS--
3259
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 1/29/15, 11:27 AM

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.

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/29/15, 11:12 AM
Seen: 972 times
Last updated: 3/16/15, 8:10 AM