Forum Discussion

MaritzaAcosta's avatar
MaritzaAcosta
Qrew Trainee
2 years ago

Formula to display someone's age based on date?

Hello I wanted to see if there was a way to calculate someone's age based on the day that they enrolled with us. I have the DOB as a date field and the Start date as well.  It would be easy to just do [DOB]- [Start Date] and get the days but I would like the answer to be displayed in years if the person is older than 1 year old and displayed in months if they are less than a year old on a Formula-Text field. Majority of Clients are Children but we also have mothers join programs. Would this be possible or is manually the only way?

Thank you in advance, I appreciate your help. 



------------------------------
Maritza Acosta Gonzalez
------------------------------
  • This makes small assumptions like a month is 30 days, and a year is 365, so will be smalll decimals off, but try this:

    var number AgeInDays = ToDays([DOB]-[Start Date]);
    var number AgeInMonths = Round(ToDays([DOB]-[Start Date]) / 30, 0.01);
    var number AgeInYears = Round(ToDays([DOB]-[Start Date]) / 365, 0.01);

    If(
     $AgeInDays<=30, ToText($AgeInDays) & " days.",
     $AgeInDays>=365,  ToText($AgeInYears) & " years.",
     ToText($AgeinMonths) & "Months."
     )



    ------------------------------
    Mike Tamoush
    ------------------------------
  • This makes small assumptions like a month is 30 days, and a year is 365, so will be smalll decimals off, but try this:

    var number AgeInDays = ToDays([DOB]-[Start Date]);
    var number AgeInMonths = Round(ToDays([DOB]-[Start Date]) / 30, 0.01);
    var number AgeInYears = Round(ToDays([DOB]-[Start Date]) / 365, 0.01);

    If(
     $AgeInDays<=30, ToText($AgeInDays) & " days.",
     $AgeInDays>=365,  ToText($AgeInYears) & " years.",
     ToText($AgeinMonths) & "Months."
     )



    ------------------------------
    Mike Tamoush
    ------------------------------