Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
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 )
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 '; } }
Referred Link: https://blog.internetcreations.com/2012/06/calculating-a-contacts-age-through-salesforce-formulas/
You can refer below example:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal