跳至內容
選單
此問題已被標幟
1 回覆
4874 瀏覽次數

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

頭像
捨棄
最佳答案

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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 22
3386
1
5月 22
2200
3
10月 15
4198
3
6月 25
1196
1
1月 25
18028