function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nikki goudnikki goud 

Age of Student

HI

how can i find the student present age(years ,months and days)
sweetzsweetz
You can use formula to find the present age of a student 

YEAR(TODAY()) - YEAR(DOB__c) -
IF(
       OR (
                  MONTH(TODAY()) < MONTH(DOB__c),
                  AND(
                      MONTH(TODAY()) == MONTH(DOB__c),
                      DAY(TODAY()) < DAY(DOB__c)
                    )
        ),
        1,
        0
)



Referred Link: https://blog.internetcreations.com/2012/06/calculating-a-contacts-age-through-salesforce-formulas/
Vatsal KothariVatsal Kothari
Hi Nikki,

You can refer below example:
trigger ContactTrigger on Contact (before insert,before update) {

	for(Contact con : trigger.new){
		
		date dt = c.Birthdate;
		
		Integer year =0;
		Integer days =0;
		Integer months = 0;
		
		//TO FIND THE AGE
		Integer totaldays = dt.daysBetween(system.today());
		year = (integer)(math.Floor(totaldays/365.2425));
		
		// TO FIND THE MONTHS
		if(dt.day() <= (system.today().day())){
			months = system.today().month()-dt.month();
		}
		else{
			months = system.today().month()-dt.month()-1;
		}
		
		//TO FIND THE REMAINING DAYS
		if((system.today().day()== dt.day()) || (system.today().day()>dt.day())){
			Days =system.today().day()-dt.day();
		}else{
			if(math.mod(system.today().month(),2) == 0){
				Days = 31-(dt.day()-system.today().day());
			}
			else{
				Days = 30-(dt.day()-system.today().day());
			}
		}
		c.Age__c = year + ' year ' + months +' months ' + days + ' days ';
	}    
}
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal