BOFocus – Crystal Reports Tips – Tricks – Tutorials

Crystal Reports - Formulas

Age calculation

The following formula will allow you to calculate a person’s age correctly:

WhileReadingRecords;
DateTimeVar begindate := CurrentDate;
DateTimeVar enddate := CurrentDate;

begindate := Date(Year(begindate), Month(begindate), 01);
enddate := DateAdd( “d”, -1, DateAdd(“m”, 1, enddate) );

If (Month(enddate) * 100) + Day(enddate) >= (Month(Date({BirthDate_Field})) * 100) + Day(Date({BirthDate_Field)) Then
Year (enddate) – Year(Date({BirthDate)) Else
Year (enddate) – Year(Date({BirthDate)) – 1;

Tagged , ,

2 thoughts on “Age calculation

  1. Sumit Saha

    The following is working perfectly OK in Crystal report
    If (Not(isNull({DataTable2.dbirth}))) Then
    ToText(int(DateDiff(‘d’,DATE({DataTable2.dbirth}),CurrentDate())/365.25),0)+’ Years ‘+
    ToText(int(remainder(DateDiff(‘d’,DATE({DataTable2.dbirth}),CurrentDate()),365.25)/30),0)+’ Months ‘+
    If day(CurrentDate()) < Day({DataTable2.dbirth}) Then
    ToText(day(dateserial(year({DataTable2.dbirth}), Month({DataTable2.dbirth})+1,1-1)) – Day({DataTable2.dbirth}) + Day(CurrentDate()),0) + ' days'
    Else
    ToText(day(CurrentDate()) – day({DataTable2.dbirth}),0) + ' days'

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

GET SOCIAL

QUICK TIP

Use the Chart Sort Order dialog box to sort and group your chart data. This dialog box appears when you click the Order button on the Data tab of the Chart Expert for a chart with the Advanced layout type.

ADVERTISMENT