0

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

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    @Pierre.. Sure is.. see https://ninoxdb.de/en/manual/calculations/reference-of-functions-and-language and browse for 

    age(Birthdate)

    • NIOXUS
    • 5 yrs ago
    • Reported - view

    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.

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

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

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    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 !

    • NIOXUS
    • 5 yrs ago
    • Reported - view

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

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    👍

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    not working, thanks anyway

    • NIOXUS
    • 5 yrs ago
    • Reported - view

    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.

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

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

    • NIOXUS
    • 5 yrs ago
    • Reported - view

    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.

    Screen Shot 2019-03-29 at 10.20.25 AM

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    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 ? :)

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    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 ? :)

    • Nick
    • 5 yrs ago
    • Reported - view

    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

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    Hello nick, still no ;)

    • Mconneen
    • 5 yrs ago
    • Reported - view

    @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)

    • Nick
    • 5 yrs ago
    • Reported - view

    Hey Pierre,

    works for me...

    Number Field: BirthYear -> e.g. 1974

    Formula Field -> Age -> year(today()) - BirthYear

    Result = 45

    • Nick
    • 5 yrs ago
    • Reported - view

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

    • Mconneen
    • 5 yrs ago
    • Reported - view

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

    ui

    birthdate0101

    AgeBirthdate0101

    • Nick
    • 5 yrs ago
    • Reported - view

    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, "")
    end

     

    The result is:

    Screen Shot 2019-03-30 at 20.33.00

    • Pierre_COLLE
    • 5 yrs ago
    • Reported - view

    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, "")
    end

    Thanks everyone for your help, have a good day :)

Content aside

  • 5 yrs agoLast active
  • 20Replies
  • 5300Views