- How to calculate the age of a person?
- How to calculate a person’s age on a particular date in Crystal Reports?
- SAP Crystal Reports 2011
- SAP Crystal Reports 2013
- SAP Crystal Reports 2016
- SAP Crystal Reports 2020
- SAP Crystal Reports for Enterprise 4.0
- SAP Crystal Reports for Enterprise 4.1
- SAP Crystal Reports for Enterprise 4.2
- SAP Crystal Reports for Enterprise 4.3
- To calculate the age of a person as of today, create a formula.
- In Crystal Reports, open the report on which you have a database field that contains birthday.
- Create a formula and enter the following code:
DateVar birthday := <INSERT THE BIRTHDAY FIELD HERE>;
DateVar vToday := Today;
// Verify if the birthday was on a leap year, and if the current year is a leap year.
If Month(birthday) = 2 and Day(birthday) = 29 Then
If not isDate(ToText(Year(vToday),0,"")+",2,29") Then
birthday := birthday + 1;
// Calculate the age
DateDiff('yyyy',birthday,vtoday) - (If Date(Year(vToday),Month(Birthday),Day(Birthday)) > vToday Then 1 Else 0)
Insert the date field in the formula where it is written: <INSERT THE BIRTHDAY FIELD HERE>
Save and close the formula.
- Insert the formula on the report where you want to display the age.
CR , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To