Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

age groups 1

Status
Not open for further replies.

3dthies

Programmer
Mar 12, 2003
77
DE
I need a formula to calculate age groups (e.g. age group 18-22, 23-29, 30-44 and so on) base on the actual date (year/month/day).
 
For Crystal 8.5, and assuming that you want to measure whole years from the date of birth to current, I'd do it by formula fields:
a) First find the difference in months, @Months:
DateDiff("m", {birth.date}, currentdate)
b) Convert this to whole years @WholeYears
Truncate((@Months/12, 0)
c) Check for birthdays in the current month but ahead of the current date, to get @TrueYears
If Datepart("m", {birth.date}) = Datepart("m", currentdate)
and Datepart("d", {birth.date}) > Datepart("d", currentdate)
then @WholeYears-1
else @WholeYears
d) Test @TrueYears for age-band
If @TrueYears < 18 then &quot;Less than 18&quot;
else if @TrueYears < 23 then &quot;18-22&quot;
etc.

Madawc Williams
East Anglia, Great Britain
 
I have CR 9.0 and the &quot;date&quot; field is an integer field, so first i have to convert it in a date field?
 
..and I have to measure not only the year. i have to measure the year, month and date
 
...the integer date date field looks like (19301025, yyyymmdd)
 
Fine. One extra point that I forgot. Check
isnull ({birth.date})
for anyone whose details may be missing.

Madawc Williams
East Anglia, Great Britain
 
d) Test @TrueYears for age-band
if isnull ({birth.date}) then &quot;Birthdate not known&quot;
else if @TrueYears < 18 then &quot;Less than 18&quot;
else if @TrueYears < 23 then &quot;18-22&quot;

Madawc Williams
East Anglia, Great Britain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top