Calculate age from date of birth in calculated field

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Calculate age from date of birth in calculated field

Post by SkayyHH » 2020-06-12 10:38

Hello,

maybe someone can give me a code for a "calculated field" on how to calculate an age from a date of birth. I tried different Selects, but unfortunately they don't work in the AppGini field "Calculated field.

Thank you very much, Kai

G Belgrado
Veteran Member
Posts: 61
Joined: 2017-03-12 09:24

Re: Calculate age from date of birth in calculated field

Post by G Belgrado » 2020-06-12 14:36


SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Calculate age from date of birth in calculated field

Post by SkayyHH » 2020-06-12 22:01

Hi,

Thanks a lot. I've already looked at the site. but I have no idea what to put in the "Calculated field".

These codes are for hooks. But what of that comes in the "calculated field" field in the appgini ide?

My fields are: "date_of_birth" and "age"

Thanks very much, Kai

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Calculate age from date of birth in calculated field

Post by pbottcher » 2020-06-14 08:22

Hi,

you can try

Code: Select all

select TIMESTAMPDIFF(year,date_of_birth,NOW()) as age from YOURTABLENAME where id=#ID#
assuming your pk is id
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Calculate age from date of birth in calculated field

Post by SkayyHH » 2020-06-14 15:56

Hi,

thank you so much for help :-)

I tried it out. But the code has no effect on the "age" field.

select TIMESTAMPDIFF(year,date_of_birth,NOW()) as age from Employees where id=#ID#

The field names should be correct

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Calculate age from date of birth in calculated field

Post by pbottcher » 2020-06-14 18:52

Hi,
can you post a screenshot of your tabledefinition and what you put into the calculated field.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Calculate age from date of birth in calculated field

Post by pbottcher » 2020-06-14 18:57

Hi, sorry, I just saw a typo in the code.

Try

select TIMESTAMPDIFF(year,date_of_birth,NOW()) as age from Employees where id=%ID%
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Calculate age from date of birth in calculated field

Post by SkayyHH » 2020-06-14 19:43

Awesome!!!

Many thanks!

Kai

Post Reply