Forum Discussion

MaritzaAcosta's avatar
MaritzaAcosta
Qrew Trainee
10 months ago
Solved

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 d...
  • MikeTamoush's avatar
    10 months ago

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