 ShowAll Questionssorted byDate Posted Balaji B 10

# how to get the date of birth ,with age years,months and days? Best Answer chosen by Balaji B 10 Nagendra Prasad Ch
Here is the code in apex,

```​date DOB = system.today();

integer days = 1;// Put days of age here
integer months = 1;// Put months of age here
integer years = 1;// Put years of age here

system.debug('DOB : '+DOB);``` Nagendra Prasad Ch
Here is the code in apex,

```​date DOB = system.today();

integer days = 1;// Put days of age here
integer months = 1;// Put months of age here
integer years = 1;// Put years of age here

system.debug('DOB : '+DOB);```

This was selected as the best answer AG_SFDC
Hi,

You can achieve this using a formula field:

Make sure formula field returns text type and replace "DOB__c" with your custom field.

```if(And(Month(Today())>= month(DOB__c), Day(Today()) >=  Day(DOB__c)),

TEXT(Year(Today())- Year(DOB__c)) &" "&"years"&" "&
TEXT(Month(Today())-Month(DOB__c)) &" "&"months"&" "&
TEXT(Day(Today())-Day(DOB__c)),

if(And(month(Today())< month(DOB__c), Day(Today())>= Day(DOB__c)),

TEXT(Year(Today())-Year(DOB__c)-1)&" "&"years"&" "&
TEXT(12 - Month(DOB__c)+month(Today()))&" "&"months"&" "&
TEXT(Day(Today())-Day(DOB__c)),

if(And( month(Today())< month(DOB__c), Day(Today())< Day(DOB__c)),

(TEXT( (Year(Today())-Year(DOB__c)-1))&" "&"years"&" "&
TEXT((12 - Month(DOB__c)+month(Today())-1))&" "&"months")&" "&
if( month(DOB__c)= 4, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 6, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 9, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 11,TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 2, TEXT( (28 - Day(DOB__c))+ Day(Today())),
TEXT( (31 - Day(DOB__c))+ Day(Today()))))))),

if(And( month(Today())= month(DOB__c), Day(Today())< Day(DOB__c)),

(TEXT(Year(Today())- Year(DOB__c)-1))&" "&"years"&" "&
"11"&" "&"months"&" "&
if( month(DOB__c)= 4, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 6, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 9, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 11,TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 2, TEXT( (28 - Day(DOB__c))+ Day(Today())),
TEXT( (31 - Day(DOB__c))+ Day(Today()))))))),

(TEXT(Year(Today())- Year(DOB__c)))&" "&"years"&" "&
TEXT(Month(Today())-Month(DOB__c)-1)&" "&"months"&" "&
if( month(DOB__c)= 4, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 6, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 9, TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 11,TEXT( (30 - Day(DOB__c))+ Day(Today())),
if( month(DOB__c)= 2, TEXT( (28 - Day(DOB__c))+ Day(Today())),
TEXT( (31 - Day(DOB__c))+ Day(Today()))))))))

)))&" "&"days"```

Let me know if it helped you! Balaji B 10