Formula for age calculation
Hello
I need to roughly calculate age of persons : (ThisYear : is there a fonction about that or do I have to put '2019' in text?)  ('TheBirthField')
What is the formula for this ?
2019('TheBirthField') doesn't work :(
Thanks a lot !
PS : If the field could be in RED when result is >65 it would be great ;)
PS 2 : if it could exclude (result stay empty) when ('TheBirthField')= empty or 1000 or 1900, that's heaven on earth :p
20 replies

@Pierre.. Sure is.. see https://ninoxdb.de/en/manual/calculations/referenceoffunctionsandlanguage and browse for
age(Birthdate)

Pierre 
The code for your "heaven on earth" solution is as follows:
let a := age('Date Field')
if ('The Birth Field' != null and 'The Birth Field' != 1000 and 'The Birth Field != 1900 then
if a >= 65 then
'Field Displaying Age' := styled(a,"red")
else
'Field Displaying Age' := a
end
end
Using and embedded If/Then structure inside of another allows you to first confirm that none of the conditions that would result in no age calcuation being performed are met. If all three of these conditions (blank, 1000 or 1900) are not true, then Ninox will calucate the age. The first line of the second If structure dictates that if the result of the age calculation is greater than or equal to 65, the result should be styled in "red". And if that If resolves to false (the age is NOT greater than or equal to 65), then the age is displayed without any color styling applied.
Welcome to heavan on earth.

Great !! I try that soon. Thanks a lot !! :)))

Hello NINOXUS,
I probably miss the simple age calculation, before the display points ;)
I actually have 2 fields : TheBirthField (full) & TheAgeField (empty).
How do I calculate the Age ? I tried '2019''TheBirthField' but it doesnt work. Do I need to create a 3d field with your formula ('AgeDisplayField') ?
Thanks !

Pierrre  You can calculate the age using the formula age(year(The BirthField))


not working, thanks anyway

Pierre  what, exactly, appears in the field 'TheBirthField'. If it is a date, then year(Field) will extract the year component of that date and age(Year) will calculate the number of years between the year of the field and the year of the current date (today). if the value of the content in TheBirthField is not a date, as formatted by Ninox, then the age calculation will not execute prooperly.

Its not a date it is just a Year (####)

In that case Pierre you need to turn that year into a date using the date(YYYY,MM,DD) function. So say for example you want to calculate age from the first day of Year (####), you would use the formula age(year(date(Year(####),01,01). You can then experiment with the MM and DD (month and day) parameters to see what impact they have on your age calculation.
See the example below.

I'm confused I can't make it work :(
I have 3 fields :
 BirthYear : 4 numbers
 Birthdate : a calculating field with this formula : date('BirthYear', 1, 1)
 Age : a calculating field with this formula : age(year(BirthDate0101))
Where am I wrong please ? :)

I'm confused I can't make it work :(
I have 3 fields :
 BirthYear : 4 numbers
 Birthdate0101 : a calculating field with this formula : date('BirthYear', 1, 1)
 Age : a calculating field with this formula : age(year(BirthDate0101))
Where am I wrong please ? :)

I hope it's OK for jumping in...
Try this
 BirthYear (number field) : 4 numbers
 Age : a calculating field with this formula : year(today())  BirthYear

Hello nick, still no ;)

@Pierre
Per the documentation .. this is the age function..
age(Birthdate)  The current age of a person with given Birthdate in years
so try age(BirthDate0101)

Hey Pierre,
works for me...
Number Field: BirthYear > e.g. 1974
Formula Field > Age > year(today())  BirthYear
Result = 45

Your "BirthYear" field is a text field or number field?

@Pierre.. here are a few screen shots showing it working

I had some time to kill, so I came up with this:
Formula field (named Age Styled in the screenshot below) with this code:
let age := year(today())  BirthYear;
if BirthYear != null and BirthYear != 1000 and BirthYear != 1900 then
styled(text(age), if age >= 65 then "red" else "green" end, "")
endThe result is:

Hello Nick, this morning I just moved my Birth years datas from text field to numbers field, my original mistake ;)
Then I applied your formula, and it works perfectly, thanks a lot.
So I just have 2 fields :
1) a number field with the years of birth : 'BirthY'
2) a formula field with Age, colorized : 'Age'. The formula inside 'Age' is :
let Age := year(today())  BirthY;
if BirthY != null and BirthY != 1000 and BirthY != 1900 then
styled(text(Age), if Age >= 65 then "red" else "green" end, "")
endThanks everyone for your help, have a good day :)
Content aside
 5 yrs agoLast active
 20Replies
 5299Views