+ Start a Discussion
lkplkp 

Leap year giving me an error in Age formula field

I have this formula to caclulate the age of an employee:


IF(ISBLANK(Birthdate__c),
0,
IF(TODAY()-DATE(YEAR(TODAY()),MONTH(Birthdate__c),DAY(Birthdate__c))<0,
YEAR(TODAY())-YEAR(Birthdate__c)-1,
YEAR(TODAY())-YEAR(Birthdate__c)
)
)

There is one person with their birthdate on on a Leap year and is giving me #ERROR in the Age field.  What can I do to add Leap year information?

Thanks.
Best Answer chosen by lkp
U JayU Jay
IF( ISNULL( BirthDate__c ) ,0.0, (TODAY()- BirthDate__c)/365.25)

I hope, this will help you. :)

All Answers

Suresh RaghuramSuresh Raghuram
do a check on the year from the date of birth by dividing it with 4 and the result equal to 0,then  if you find it as a leap year do not apply the above condition and change your formula such that it will generate the result you are looking for.

If((Date.year() / 4 == 0),(
calcutate the DOB;
,
IF(ISBLANK(Birthdate__c),
0,
IF(TODAY()-DATE(YEAR(TODAY()),MONTH(Birthdate__c),DAY(Birthdate__c))<0,
YEAR(TODAY())-YEAR(Birthdate__c)-1,
YEAR(TODAY())-YEAR(Birthdate__c)
)
)
)


Shashikant SharmaShashikant Sharma
See this : https://developer.salesforce.com/forums/ForumsMain?id=906F00000008ugXIAQ
Pratik_MPratik_M
Hi,

You can refer to the Knowledge Article: https://help.salesforce.com/apex/HTViewSolution?id=000004939&language=en_US

Thanks,
Pratik
U JayU Jay
IF( ISNULL( BirthDate__c ) ,0.0, (TODAY()- BirthDate__c)/365.25)

I hope, this will help you. :)
This was selected as the best answer
lkplkp

Yes that worked!  Thank you.

One more question:

We also have a birth month formula flield and I am getting the same error for the Leap year date (#ERROR!)  The birthdate is 2/29.  
DATE( YEAR( DATEVALUE( NOW() ) ) , MONTH( Birthdate__c ) , DAY( Birthdate__c ))

How can I fix this for the birth month?

Thanks!