anusha(salesforce developer)

Tuesday 14 June 2016

Calculating Age From Date of Birth

 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.

No comments:

Post a Comment