I am trying to run a report for all patients age 21 and under to monitor well child visits. I am running this in Crystal Reports. I have the below formula to use to convert the DOB to age. For some reason, I have a category listed as Others that has quite a few patients listed whose DOBs are not converting to age in either months or years. Some of the ages of these patients are in weeks while others are 11 months, 12 months, 15 months, 17 months, and 20-23 months. Can anyone please help me with this? I'm not sure what is wrong with the formula.
Formula from Crystal Report:
// Formula to express age in months if less than 2 years
// else express in years
// Subtract Year of birth from Current Year to estimate
// age in years
NumberVar AgeInYears := Year(CurrentDate) - Year({PatientProfile.Birthdate});
// Determine if Birthday has already occurred by
// subtracting Month of Birth from Current Month
NumberVar Months := Month(CurrentDate) - Month({PatientProfile.Birthdate});
// Determine if Birthday has already occurred by
// subtracting Day of Birth from Current Day
NumberVar Days := Day(CurrentDate) - Day({PatientProfile.Birthdate});
// Subtract date of birth from current date to
// determine age in days
NumberVar AgeInDays := CurrentDate - {PatientProfile.Birthdate};
// If Age in Days is less than 30, express as less
// than 1 month
if AgeInDays < 30 then
"<1 Month"
else
// If Age in Weeks is less than 60, express as < 2 months
if (AgeInDays) < 60 then
"<2 Months"
else
// If current year minus year of birth is <2, express
// age in months
if (AgeInYears < 2) Then
// If month of birthday has not occurred this year,
// subtract 1 from age in years and figure months of age
(If Months < 0 Then
(Months := Months + 12;
AgeInYears := AgeInYears - 1;);
// If month of birthday has occurred but day of
// birthday has not occurred this year, subtract
// 1 from months
if (Days < 0) Then
Months := Months - 1;
ToText(Months + (AgeInYears * 12), 0) + " Months";)
else
// If current year minus year of birth = 2, check to
// see if birthday has not occurred this year
if (AgeInYears = 2 and (Months < 0 OR (MONTHS = 0 AND Days
< 0))) Then
(If Months < 0 Then
(Months := Months + 12;
AgeInYears := AgeInYears - 1;);
if (Days < 0) Then
Months := Months - 1;
ToText(Months + (AgeInYears * 12), 0) + " Months";)
else
// If current year minus year of birth is >2, check
// to see if birthday has not occurred this year
(
if (Months < 0 OR (MONTHS = 0 AND Days < 0)) then
AgeInYears := AgeInYears - 1;
ToText(AgeInYears, 0);
)
Thanks!
Rebecca Higdon
UT Graduate School of Medicine-Family Medicine
Confused why you could not simply do something like:
(DateDiff ("m",{PERSON.DATEOFBIRTH} , today))/12
which would give you a decimal representation of a person's age, rounded to the nearest month.