- 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 2008
- SAP Crystal Reports 2011
- SAP Crystal Reports 2013
- SAP Crystal Reports 2016
- 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 BusinessViews Manager , How To