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!

Calculate and Group by Age in Years and Months

Status
Not open for further replies.

jemsmom

IS-IT--Management
May 31, 2005
43
US
I need to group a report by the patients age at the time of the surgery by using the birth date and surgery date. The age needs to be in months and years.

The groups needs to be:
< 1 Month,
1 - 6 Months,
6 months - 2 Years,
2 - 12 Years,
12 - 18 years,
> 18 Years

Any and all help is appreciated.

Thank you!
 
Make a formula using datediff, then group by that formula. Have the group in specialized order and set up your conditions for each grouping.

I hope this helps.
 
Here is my formula for age based on today's date:

{@AGE}
DateDiff("yyyy", {TABLENAME.BIRTHDATE}, CurrentDate)

This is calculating in years so if you are looking for months, change "yyyy" to "mm".

Next, formula for grouping ages together:

{@AGE_RANGE}
IF {@AGE} < 18 THEN "under 18" ELSE
IF {@AGE} in 18 to 29 THEN "18 to 28" ELSE
IF {@AGE} in 29 to 39 THEN "29 to 38" ELSE
IF {@AGE} in 39 to 49 THEN "39 to 48" ELSE
IF {@AGE} in 49 to 59 THEN "49 to 58" ELSE
IF {@AGE} >= 59 THEN "over 58"

You can easily modify this for months and the groupings you are wanting to use.

I hope this helps.


FireGeek
(currently using Crystal Reports XI with Lawson 8.03)
 
That's not a good formula to use for age, as it doesn't take into account the month--in other words, if I was born in May, your formula would make me one year older than I really am right now.

Ken Hamady has a good formula for years on his website: in his formula section. For age under 1, I think you would have to first decide what you mean by '1 month' and then do a datediff formula based on days and divide by the monthly figure.

-LB
 
There is a formula that was in the help for Crystal XI that I have used for a number of years. I do not remember how I came across it. It even takes in account for the day of the month.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top