This is a public Forum  publicRSS

Forum post

    Larry Beatty
    Calculating an age in years based on a specific dateAnswered
    Forum post posted December 26, 2010 by Larry Beatty, last edited February 9, 2012 
    210 Views, 4 Comments
    Title:
    Calculating an age in years based on a specific date
    Post:

    I have a regular age calculation that works fine based on birthdate, but I am looking for a calculation that will give an age based on a specific date. For example what age (in years) will a person be on August 31, 2011. Appreciate any help.

    Best Answer

    PhilModJunk

    most age calculations use an expression similar to this:

    Let ( [
              Today = Get (CurrentDate) ;
              bDay = Date ( Month ( BirthdateField ) ; Day ( BirthdateField ) ; Year ( Today ) );
              Age = Year ( Today ) - Year ( BirthdateField ) - ( Today < bDay )
             ] ;
             If ( Age > 0 ; Age ; "" )
            )

    Because Get ( CurrentDate ) is used, this calculation must be unstored.

    To use a different date other than Today, simply modify the first part of this expression, Today = .... to refer to a date field where you specify this different date:    Today = DateField

    Answer

     

    • ishulman

      Larry,

      Would like to help you out, but your request is beyond my knowledge. However, I was wondering if you'd be willing to share your coding to compute age calculations? I was only able to base my calculation on the year of birth, meaning that the resulting ages are inaccurate when the current date precedes the date of the birth.

      Ishulman@shiftct.com

    • PhilModJunk

      most age calculations use an expression similar to this:

      Let ( [
                Today = Get (CurrentDate) ;
                bDay = Date ( Month ( BirthdateField ) ; Day ( BirthdateField ) ; Year ( Today ) );
                Age = Year ( Today ) - Year ( BirthdateField ) - ( Today < bDay )
               ] ;
               If ( Age > 0 ; Age ; "" )
              )

      Because Get ( CurrentDate ) is used, this calculation must be unstored.

      To use a different date other than Today, simply modify the first part of this expression, Today = .... to refer to a date field where you specify this different date:    Today = DateField

    • Larry Beatty

      Ishulman,

      This is what I used for age that works well for us.

      Let ( [now = Get ( CurrentDate ) ;thisBD = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( now ) ) ;passed = now < thisBD ] ;Year ( now ) - Year ( DOB ) - passed)

    • Larry Beatty

      Thanks Phil. That works awesome. Just what I needed!