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.

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 752 views

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

3

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

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

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

1 follower(s)

Stats

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