SAP Knowledge Base Article - Public

1538006 - How to calculate a person’s age on a particular date?

Symptom

How to calculate a person’s age on a particular date?

Environment

  • Crystal Reports XI R2 (All Patch levels)
  • Crystal Reports 2008 (All Patch levels)

Resolution

  1. Create a Crystal Report (You may chose not to select any data source)
  2. Create a Static Parameter (Field Explorer -> Right Click Parameter Fields ->New) and call it ‘Birthday’
  3. The data type of the Parameter should be ‘Date’
  4. Create another Date Parameter and call it ‘Effective Date’
  5. Create a new formula (Field Explorer ->Right click ‘Formula fields’ ->New) as follows:
  6. datediff('yyyy',{?Birthday},{?Effective Date}) - (if datepart('y',{?Effective Date})>=datepart('y',{?Birthday}) then 0 else 1)

  7. Save this formula and drag it onto the Report Header section
  8. Refresh the report and enter your birth date in the ‘Birthday’ Parameter and any date in the ‘Effective Date’ Parameter
  9. For e.g.: if your birth date is 18/2/1987, select 18/2/2011 in the ‘Effective Date’ Parameter and the result should be ‘24’ which is accurate

Keywords

Calculate age, Crystal Reports , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

Product

Crystal Reports 2008 V0 ; Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2