Everyone knows that it’s poor etiquette to ask someone their age, and even worse to skew it in the wrong (read: upward) direction when you do need to confirm it. There’s a bunch of formulas out there for calculating someone’s age (or just the number of years between any two dates), but the simple ones have a tendency to be off by as much as a week or more, and the more complicated ones can be difficult to understand if you find a bug. Your team shouldn’t have to stop and do the math before asking that ever difficult question, and they shouldn’t have to go red in the face wishing a happy 21st birthday to someone who’s already been to the bar. You especially don’t want to send someone a Senior Citizen’s discount too early or offer an insurance package they’re not eligible for. You need a simple, clean formula that gets it right every time. Look no further!
This gem comes to you from the Developerforce Cookbook site and essentially operates on the principal of the Futurama Birthday Song (what day is today; it’s so-and-so’s birthday). All you need is a date field (here, they’ve used a custom field called DOB) and you’re ready to create your formula. IF( MONTH(TODAY())>MONTH(DOB__c), YEAR(TODAY())-YEAR(DOB__c), IF(AND(MONTH(TODAY()) = MONTH(DOB__c), DAY(TODAY()) >= DAY(DOB__c)), YEAR(TODAY())-YEAR(DOB__c), (YEAR(TODAY())-YEAR(DOB__c))-1) ) . With this formula you’ll always have the right age.
-Jared and the Salesforce Guys