Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4858 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 22
3385
1
mai 22
2196
3
oct. 15
4198
3
iun. 25
1192
1
ian. 25
18028