Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted

# Formula field for calculate age by using DOB

HI All,

How to create a fomula field for my age field ? It will be calculated by using the Date_of_Birth__c field. I have a fomula.

`IF(MONTH(TODAY())>MONTH(DOB_API),YEAR(TODAY())-YEAR(DOB_API),IF(AND(MONTH(TODAY())=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)),YEAR(TODAY())-YEAR(DOB_API),(YEAR(TODAY())-YEAR(DOB_API))-1))  `

That's from Ankit's blog. But I don't know how to use it and where to use it.

Shashikant Sharma

Yes thats a correct formula , you can use above

If you want to go for smaller formula

Use this one : From http://forceschool.blogspot.com/2011/06/age-calculation-formula.html﻿

`IF(ISNULL(DOB__c) , DOB__c , FLOOR((TODAY()-DOB__c +1)/365.2425))`

Now to your question how to use it.

1) Create a formula field return type Integer

2) Use any of the formula , replace your date field API Name with DOB__c

Then you will see this Calculated Age in your formula field.

Shashikant Sharma

Yes thats a correct formula , you can use above

If you want to go for smaller formula

Use this one : From http://forceschool.blogspot.com/2011/06/age-calculation-formula.html﻿

`IF(ISNULL(DOB__c) , DOB__c , FLOOR((TODAY()-DOB__c +1)/365.2425))`

Now to your question how to use it.

1) Create a formula field return type Integer

2) Use any of the formula , replace your date field API Name with DOB__c

Then you will see this Calculated Age in your formula field.

This was selected as the best answer
Ankit Arora

@Chamil Good to know someone is reading my blog :)

@Shashikant Thanks for sharing this sort trick and it worked for me too, but there was a small change :

I have converted the return type from integer to text and formula to :

`IF(ISNULL(SLAExpirationDate__c) , TEXT(SLAExpirationDate__c) , TEXT(FLOOR((TODAY()-SLAExpirationDate__c +1)/365.2425)))`

As I was unable to compile the formula provided.

Thanks

Ankit Arora

Ramakrishnan Ayyanar
Problems:

1)If DOB is Feb 29 Leap year.How to find next birthday for that particular date?

No Need Validation rule for this code.

End-of-century years 1700, 1800,1900,2100 these years are not leap year in these problems are resolved.........

To find the next Birthday formula

How to create......

step-1: create the custom field for Date of Birth----It's type-Date

step-2: create the formula field for Birthday ---It's type-Date

code:

if(
MONTH(ramki__DOB__c) = 2 &&
DAY(ramki__DOB__c) = 29 ,
DATE(IF(Year(today())<=Year(ramki__DOB__c),
Year(ramki__DOB__c),
IF(
OR(MOD(Year(today())+4-MOD(Year(today()),4),400)=0,
AND(MOD(Year( today())+ 4-MOD(Year(today()),4),4)=0,
MOD(Year(today())+ 4-MOD(Year( today()),4),100)<>0)),
Year(today())+ 4-MOD(Year( today()),4),
Year(today())+ 8-MOD(Year( today()),4))
),
MONTH(ramki__DOB__c),DAY(ramki__DOB__c)),
if(Year( today()) <= Year( ramki__DOB__c)  ,
DATE(Year(ramki__DOB__c),MONTH(ramki__DOB__c),DAY(ramki__DOB__c)) ,
IF (DATE (YEAR(TODAY()),MONTH(ramki__DOB__c),DAY(ramki__DOB__c)) > TODAY(),
DATE (YEAR(TODAY()),MONTH(ramki__DOB__c),DAY(ramki__DOB__c)),
DATE (YEAR(TODAY())+1,MONTH(ramki__DOB__c),DAY(ramki__DOB__c))
)))

it's correctly worked for leap year dates.......
this is code for find the next Birthday friends......

Easily Calculate Age:

create formula field -------(Number)

Age=YEAR( ramki__BirthDay__c) - YEAR(ramki__DOB__c)
----
softramki@gmail.com
+919944112175
Srinath Reddy 23
The below formula calculates exact age including leap year as posted on Knowledge Article Number000230455...!

IF( NOT( ISBLANK( Birthdate ) ) ,
2  IF( DATE( 2000 , MONTH( Birthdate ) , DAY( Birthdate ) ) <= DATE( 2000 , MONTH( TODAY() ) , DAY( TODAY() ) ),
3     YEAR (Today()) - YEAR ( Birthdate ),
4     YEAR (Today()) - YEAR ( Birthdate ) -1 ),
5  null)

Thanks.

Vishal Thube
Use Simple Formula If You show only Age

1) Create a formula field return type "Number"
2) Use Formula i below mentioned  , replace your date field API Name with DOB__c

( TODAY() - DOB__c )/365

..
AnnieE
Really happy to have found this thread. My brain is pretzeled trying to work out the formula for a custom Age field based on DOB expressed as "x yrs, x mos, x wks, x days" for any age under 1yr.  This field refrences the age of animals so being able to display age in months, weeks and days is important for animals under a year old. Any advice would be greatly appreciated!! Thanks in advance.
jebof marya
excellent information that is quite helpful to me, therefore I appreciate
you sharing  Myeclass Login (https://gab.com/myeclass/posts/110672353487088811" target="_blank)