Tuesday 31 May 2011

Calculating Age From Date of Birth

Recently I got inspired from one of my favorite technical article spot (http://forceguru.blogspot.com/2011/05/calculating-age-from-birth-date.html) for calculating Age of from Date of Birth. Here I have added some flexibility for getting age up to month Level just copy and paste following code in your formula field  (which should be of number type).of years
**********************************************************************************

If(
   OR(
      And(
           MONTH(TODAY())>=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)
     ),
      And(
  MONTH(TODAY())>MONTH(DOB_API),DAY(TODAY())<DAY(DOB_API )
         )
      ),
         (YEAR(TODAY())-YEAR(DOB_API)),
         If(
            OR(
               And(
                   MONTH(TODAY())<=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)
                  ),
               And(
                  MONTH(TODAY())<=MONTH(DOB_API),DAY(TODAY())<DAY(DOB_API)
                  )
              ),
         (YEAR(TODAY())-YEAR(DOB_API )-1),
0
           )
)


**********************************************************************************
and for months copy and paste following code in your formula field (which should be of number type).of months.
**********************************************************************************


If(
   OR(
      And(
           MONTH(TODAY())>=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)
      ),
      And(
   MONTH(TODAY())>MONTH(DOB_API),DAY(TODAY())<DAY(DOB_API )
         )
      ),
        MONTH(TODAY())-MONTH(DOB_API) ,
         If(
            OR(
               And(
                   MONTH(TODAY())<=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)
                  ),
               And(
                  MONTH(TODAY())<=MONTH(DOB_API),DAY(TODAY())<DAY(DOB_API)
                  )
              ),
        (12-MONTH(DOB_API ))+MONTH(TODAY()) ,
0
           )
)

**********************************************************************************
Here You will get Age in years like if your DOB is 5/8/1990 then Today(31/5/2011) then your age would be 20 years 9 months.

I would like to refer great thanks and whole credit to Mr. Ankit Arora dropping focus on this topic.
Source : http://forceguru.blogspot.com/2011/05/calculating-age-from-birth-date.html

No comments:

Post a Comment