Calculating Age

Hi, guy. i want to calculate my employees’ age, my date of birth format is “YYYY-MM-DD”
I want to use custom script.

Cheers
Jack

Hi,

You can check the following discuss thread for the same: Calculate Employee age from Date of Birth

Hope this helps.

Yeah, Michelle. but i think this code is too long. Do you have any simpler version of code?

Best Wishes
Jack

hey @jack_qi ,

cur_frm.set_value(AgeField, moment().diff(DOBfield, 'years'));
cur_frm.refresh_field(AgeField)

simpler version of code.

2 Likes

Thanks a lot.

Hi All,

Good day!

We have custom field “age” with data field type in employee doctype I want to auto compute age value base on “date_of_birth” field, we are using ERPNEXT v13, is anyone can fixed this?
I tried the scipt above create to the “Client Script”

cur_frm.set_value(age, moment().diff(DOBfield, ‘date_of_birth’));
cur_frm.refresh_field(age)
I got error message

ReferenceError: age is not defined
    at eval (employee__custom_js:1:19)
    at init.setup (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1133682)
    at frappe.ui.form.Form.setup (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1182856)
    at frappe.ui.form.Form.refresh (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1186006)
    at frappe.views.FormFactory.render (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1091641)
    at frappe.views.FormFactory.show_doc (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1091203)
    at frappe.views.FormFactory.make (http://192.168.200.60/assets/js/form.min.js?ver=1621516672.0:1:1090134)
    at frappe.views.FormFactory.show (http://192.168.200.60/assets/js/desk.min.js?ver=1621516672.0:1:368742)
    at Object.render_page (http://192.168.200.60/assets/js/desk.min.js?ver=1621516672.0:1:97566)
    at Object.render (http://192.168.200.60/assets/js/desk.min.js?ver=1621516672.0:1:97293)

Thanks