Wednesday 11 December 2013


Calculate number of years in formula field

If you want to calculate number of years between two dates like calculating someone's age in years from his/her birthdate, you can do it using formula field.

 Create a formula field and select return type a number, don't forget to select decimal place to 0. Now in Formula field editor write below formula.





 Explaination:

IF condition first checks if month of present year is greater than date of birth, if condition is true then age will be calculated as the difference between present year and year of birth, but if condition is false then second IF condition is calculated according to which if month of two dates are same or taday's day is larger than or equal to the day of date of birth then age is calculated as in the first scenario [ YEAR(TODAY()) - YEAR(TODAY()) ]. If these also fail then age is calculated as the difference between present year and year of birth, subtracting 1 
[ YEAR(TODAY()) - YEAR(DOB__c) -1 ].

No comments:

Post a Comment