Page 1 of 1

Calculate age

Posted: Tue Mar 03, 2020 5:40 pm
by GlenMcCabe
I need to calculate age from date of birth input. Any help appreciated.

Re: Calculate age

Posted: Tue Mar 03, 2020 9:42 pm
by Janusz

Re: Calculate age

Posted: Tue Mar 03, 2020 11:35 pm
by Janusz
or with mysql
https://stackoverflow.com/questions/577 ... sql-innodb

you can use on edit form Display field for example:
and for initial trial you can place directly in the Display -> Display/SQL field following code from above link:

Code: Select all

SELECT TIMESTAMPDIFF(YEAR, '1970-02-01', CURDATE()) AS age
(here you can refer to any table values from your DB)

you can place the following in the browse table display inside brackets():

Code: Select all

(SELECT TIMESTAMPDIFF(YEAR, '1970-02-01', CURDATE()) AS age)
or with reference to your data ex:
(SELECT TIMESTAMPDIFF(YEAR, cut_birth, CURDATE()) AS age)

Re: Calculate age

Posted: Tue Mar 03, 2020 11:42 pm
by GlenMcCabe
Thanks Janusz.

Will try these

Re: Calculate age

Posted: Wed Mar 04, 2020 9:00 am
by kev1n
Pros and cons (Display Object vs JavaScript)

Display Object:

[-] Is only refreshed after the form is saved
[+] It's easy to use

Using JavaScript:

[+] Age can be calculated at any time, even before the form is saved.
[-] Need JavaScript knowledge, maybe a date conversion nevessary.