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
SIVASASNKARSIVASASNKAR 

calculate Age, Monts, Days from birth day

how to calculate Age, Months, Days from Birthdate to Current Date?

Best Answer chosen by Admin (Salesforce Developers) 
Baktash H.Baktash H.

Date today = Date.Today();
System.Debug('++++' + today.year());
System.Debug('++++' + today.month());
System.Debug('++++' + today.day());

All Answers

Baktash H.Baktash H.

Date today = Date.Today();
System.Debug('++++' + today.year());
System.Debug('++++' + today.month());
System.Debug('++++' + today.day());

This was selected as the best answer
SIVASASNKARSIVASASNKAR

Thanks for  your answer with the help of your methods i develop the code for calculating age,months and remaining days from date of birth. 

 

//THE CODE HELPS FOR CALCULATING AGE, MONTHS AND REMAINING DAYS

 

Contact c=Trigger.new[0];
date dt=c.Birthdate;

//TO FIND THE AGE
Integer totaldays=dt.daysBetween(system.today());
c.Age__c=(integer)(math.Floor(totaldays/365.2425));
// TO FIND THE MONTHS
if(dt.day()<=(system.today().day()))
c.months__c=system.today().month()-dt.month();
else
c.months__c=system.today().month()-dt.month()-1;
//TO FIND THE REMAINING DAYS
if((system.today().day()== dt.day())||(system.today().day()>dt.day()))
c.Days__c=system.today().day()-dt.day();
else
{
if(math.mod(system.today().month(),2)==0)
c.Days__c=31-(dt.day()-system.today().day());
else
c.Days__c=30-(dt.day()-system.today().day());
}

 

 

 

IF IT IS RIGHT PLEASE SEND ME REPLAY 

 

THANKS AND REGARDS

SIVASANKAR DEVELOPER.