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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate dob for age range 1

Status
Not open for further replies.

RenaG

Programmer
May 3, 2011
132
US
I am using Crystal 10.

How would you calculate a date range if given the request:
I want a report of all males between 18 - 50 years of age.

TIA,
~RLG
 
Hi LB,

That got me started but I have run into a hiccup. I added the code on Ken Hamandy's page in the @age function using
Code:
DateVar Birth := Date({Patient.Birth_DtTm});
DateVar Ann := CurrentDate;

I placed this Formula on the report and it seems to be calculating correctly and sees it as a number.

But when I reference it in the record selection formula like this:
@age in (18.00 to 50.00)

It says there is an error in the formula:
A number, currency amount, boolean, date, time, date-time, or string is expected here
I have tried several ways of asking this question, such as:
@age >= 18 and @age <= 50
And they all get the same error message. When I mouse over it on the report is says it is a number so I don't understand why it gives this error. Any suggestions?

TIA,
~RLG
 
You are not showing the entire formula from Ken's page. Please show the actual formula you used for {@age} if it contained more that what you are showing above.

-LB
 
Good morning!

Here is the entire formula:
Code:
WhileReadingRecords;
DateVar Birth:= Date({Patient.Birth_DtTm});   // Replace this with your field for Date Of Birth
DateVar Ann := CurrentDate;  // Replace this with CurrentDate to get their age as of the time of the report
  //or the date field of an event to get their age as of the time of that event.
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)  
then Year (Ann) - Year(Birth)  
else Year (Ann) - Year(Birth) -1

Did I miss anything?

~RLG
 

Just noticed that you didn't use square brackets, but you don't need any at all:

@age in 18 to 50

And you don't need decimals, since the result is always a whole number. If you did want to use brackets, it would be:

@age in [18 to 50]

-LB

 
Argh! I just figured out what was wrong. I did not have the curly braces around @age! So at least I can save it. Now to test it to see if it works!

Thanks for all your help!

~RLG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top