Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

PDF exPLODE

Calculating an accurate Age:

I was surprised that this formula needed to be written.   The problem with calculating age is that it is calculated as an integer, and always rounded down.  If you are 20 years and 364 days old, you are considered 20. The next day you gain one whole year in age.   My old formula was simply to subtract date of birth from current date and divide by 365.25.  The result is pretty accurate as long you are showing some decimal places and not rounding up.   But in testing this accross leap years I found that about 1 out of 1000 people could be listed as one year younger than they are, for one day.    To get a reliable Integer age you can use the formula below.
WhileReadingRecords;
DateVar Birth:= {ages.Birth};   // Replace this with your field for Date Of Birth
DateVar Ann := {ages.DateAnn};  // Replace this with CurrentDate to get their age as of the time of the report
                                                            //or the date field of an event to get their age as of the time of that event.
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth) 
then Year (Ann) - Year(Birth) 
else Year (Ann) - Year(Birth) -1