4 Replies Latest reply on Feb 18, 2009 11:50 PM by krempch

    How do I compute someone's age in MONTHS?

    krempch

      Title

      How do I compute someone's age in MONTHS?

      Post


      <!-- GALLERYINCLUDE -->How do I compute a child's age in months?
      I have two DATE fields to compute the age from,

      child_dob   and    school_date
       
      both are 4-digit dates. I am not sure if I should use a Calculation field or scripting logic.

       

      Thanks in advance for advice.<!-- POLLS --><!-- FILES --><!-- SIGNATURE -->




        • 1. Re: How do I compute someone's age in MONTHS?
          synergy46
             //The Age function will calculate a persons age, on any date, in three different formats -
          //     1 / Years
          //     2 / Years and Days
          //     3 / Years, Months and Days.

          Let ( leapFactor = If ( Mod ( Year ( theDate ) ; 4 )  = 0 ; 1 ; 0 );


          Case (

          // Age in years
          Format = 1 ; Year ( theDate ) - Year ( Birth ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( Birth ) );


          // Age in years and days
          Format = 2 ; Year ( theDate ) - Year ( Birth ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( Birth ) ) & " years and " & Case (
          ( DayOfYear ( theDate ) - leapFactor ) ≥ DayOfYear ( Birth ) ; DayOfYear ( theDate ) - leapFactor - DayOfYear ( Birth )  ;
          DayOfYear ( theDate ) + ( DayOfYear ( Date ( 12 ; 31 ; Year ( theDate ) ) - DayOfYear ( Birth ) - leapFactor ) ) ) & " days" ;


          // Age in years, months and days
          Format = 3 ;  Year ( theDate ) - Year ( Birth ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( Birth ) ) & " years and " & Mod ( Month ( theDate ) - Month ( Birth ) + 12 - (Day ( theDate ) < Day ( Birth ) ) ; 12 ) & " months, and " & (theDate - Date ( Month ( theDate ) - (Day ( theDate ) < Day ( Birth ) ) ; Day ( Birth ) ; Year ( theDate ) ) ) & " days"

          )
          )











          • 2. Re: How do I compute someone's age in MONTHS?
            bluegeek
              

            An engineer friend suggested the following :

             

            (end_date - begin-date) / 30.4 

             

            Round as you see fit.

            • 3. Re: How do I compute someone's age in MONTHS?
              davidhead
                

              Try this calculation:

               

              Let ([

                startdate = child_dob;

                enddate = school_date;

                startmonth = Month (startdate);

                startyear = Year (startdate);

                endmonth = Month (enddate);

                endyear = Year (enddate)

              ];

                 (12 - startmonth) +                           // months in first year

                 ( endyear - startyear - 1 ) * 12 +   // months in intervening years

                 endmonth                                          // months in end year

              )

               

               

              • 4. Re: How do I compute someone's age in MONTHS?
                krempch
                   Thank you ... will do!