Smart questions
Smart people
 Find A ForumFind An Expert
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips now!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Just copy and paste the

#### Feedback

"...I just wanted to say THANKS for the forum. The knowledge I gain from your site is invaluable..."

#### Geography

Where in the world do Tek-Tips members come from?

# Calculate dob for age range

 Forum Search FAQs Links Jobs Whitepapers MVPs
 RenaG (Programmer) 12 Mar 12 14:07
I am using Crystal 10.

How would you calculate a date range if given the request:

#### Quote:

I want a report of all males between 18 - 50 years of age.

TIA,
~RLG

 lbass (TechnicalUser) 12 Mar 12 15:04
 Create a formula {@age} as shown here: http://www.kenhamady.com/form06.shtmland then use a record selection formula like:{table.gender} = "M" and{@age} in 18 to 50-LB
 RenaG (Programmer) 12 Mar 12 15:42
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:

#### Quote:

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

 lbass (TechnicalUser) 12 Mar 12 20:28
 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
 RenaG (Programmer) 13 Mar 12 10:09
Good morning!

Here is the entire formula:

#### CODE

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

 lbass (TechnicalUser) 13 Mar 12 12:58
 Just noticed that you didn't use square brackets, but you don't need any at all:@age in 18 to 50And 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
 RenaG (Programmer) 13 Mar 12 13:11
 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

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!