1 Reply Latest reply on Jan 8, 2010 4:43 AM by thumper

    Calculate age

    thumper

      Title

      Calculate age

      Post

      I have animalsin my database with a birthday field, is there a way to calculate the total age of  the animal so the field i have called "current age" would show the following :

       

      ex: 1 year, 4 months, 22 Days

       

       

      im currently using the following calculation for this field:

       

      If ( Month ( Get ( CurrentDate )) < Month (Reptile DOB) ; Year ( Get ( CurrentDate ) ) - Year ( Reptile DOB ) - 1 ; Year ( Get ( CurrentDate ) ) - Year ( Reptile DOB ) )

       

       

      and if the animal is under a year or less the then one month old, then it should show as:

       

      ex: 0 Years, 0 Months, 3 Days

       

       

      i tried using the code above and changing it to show the months and days as well but it just messed it up.

        • 1. Re: Calculate age
          thumper
            

          I found the answer for this one today, doing some extensive research.

           

           

          for anyone who wnats to know how here it is:

           

           

          go to file>>>>manage>>> manage custom functions

           

          then create a new custom function and paste in the following:

           

          GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( Birthdate ) - If ( Get ( CurrentDate ) <  Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( Birthdate ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Birthdate ) ; 1 ; 0 ) ; 12 ) ) & " Months, " & GetAsText ( Day ( Get ( CurrentDate ) ) - Day ( Birthdate )  + If ( Day ( Get ( CurrentDate ) )  ≥ Day ( Birthdate ); 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( Birthdate ) ; Day ( Birthdate ) ; Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) ) ) ) & " Days " 

           

           

           

          then when you have your calculation field ready to go use the above custom function as your calculation, set your parameters and for this one be sure to set your calculation results to "Text" or else it wont work.