4 Replies Latest reply on Sep 19, 2011 8:13 AM by joaol

    Calculate age

    joaol

      Title

      Calculate age

      Post

      I try to find out a formula to calculate UPDATE age,,, here is the formula I use right now

      Year(Get(CurrentDate)) - Year(DateOfBirth)

      but it will not update, for example:

      DateOfBirth = 09/18/1980
      Today= 09/17/2011

      so,, today age is 29

      it should turn to 30 tomorrow,,, but the formula wont update the age..... any solution, thank you

        • 1. Re: Calculate age
          LaRetta_1

          If someone's birthday is 9/21/1980, your calc shows them 31 when they are actually still 30 (they won't turn 31 for few more days).

          I would suggest a calculation such as this which adjusts to allow for it:

          Let ( [
          today = Get(CurrentDate) ;
          b = dob
          ];
          Year ( today ) - Year( b ) -  ( ( Month ( today ) + Day ( today ) / 100 ) < ( Month ( b ) + Day ( b ) / 100 ) )
          )

          Be sure to go into this calculations Options (and then Storage Options) and uncheck 'do not store calculation results' so it will update.  This is probably why yours wouldn't update as well. :^)

          • 2. Re: Calculate age
            alanfink@comcast.net

            Here is a function that I use for determining age.  Accurate, and accounts for things like leap years, current day, etc.

            http://www.briandunning.com/cf/518

             

            • 3. Re: Calculate age
              LaRetta_1

              That function, amfca, lists as years months and days whereas joaol l wanted just number of years.

              joaol l, you can also just use this:

              Let ( [
              today = Get(CurrentDate) ;
              b = dob
              ];
              Year ( today ) - Year( b ) -  ( today < Date ( Month ( b ) ; Day ( b ) ; Year ( Get ( CurrentDate ) ) ) )
              )

              And yes, both the calcs I presented account properly for leap year and neither require a custom function.  If I were to do a calc which listed years, months and days, I would write the calc this way (which properly adjusts to drop the 's' if the result is singular, doesn't have to be a custom function so anyone can use it, adjusts for leap year, and is accurate):

              Let ( [
              start = theDate ; // list your birthday field in place of theDate
              next = Date ( Month ( start ) + 1 ; Day ( start ) ; Year ( start ) ) ;
              end = Get ( CurrentDate )  ;
              x = 12 * ( Year ( end ) - Year ( start ) ) + Month ( end ) - Month ( start ) - ( Day ( end ) < Day ( start ) ) ;
              y = Div ( x ; 12 ) ;
              m = Mod ( x ; 12 )  ;
              d = Case ( Day ( start ) > Day ( end )  ; Day ( next - Day ( next ) ) +  Day ( end )  - Day ( start )  ; Day ( end ) - Day ( start ) ) ;
              string = Case ( y ; y & " year" & Case ( y > 1 ; "s" ) & ", " ) &
              Case ( m ; m & " month" & Case ( m > 1 ; "s" ) & ", " ) &
              Case ( d ; d & " day" & Case ( d > 1 ; "s" ) )
              ] ;
              LeftWords ( string ; Length ( string ) )
              ) // END LET

              • 4. Re: Calculate age
                joaol

                thanks, finally, I find out that I forget uncheck....Tongue out