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

Calculating Age

Status
Not open for further replies.

KalebsDad78

Technical User
May 6, 2006
57
US
Hi All,

I am working on a report where I am trying to calculate patient's age and my age data (DOB field) is a "string" field.

I have tried the Ken Hamady formula and it tells me, when inputing the "Customers.dob" field that a "date is required here."

How can I get this formula to work or change this string field to an integer? Or is there another formula I can use to achieve the same results?
 
You need to show us samples of the string field that demonstrate the variation in instances of the field.

-LB
 
The date of service field and the DOB field appear as:

2009-08-04 and indicate they are strings.
 
You should be able to convert the field to a date by using this:

date({table.stringdate})

In Ken's formula, just wrap your field in date() and see if it works correctly. Should.

-LB
 
Ok, I tried that and I keep getting "The ) is missing."

Here is what I have:

WhileReadingRecords;
DateVar Birth:= date(val(left(date({Trips.tdate})),4),val(mid((date({Trips.tdate})),5,2)),val(right(((date{Trips.tdate})),2)));
DateVar Ann := date({Customers.dob});
if (Month(Ann) * 100) + Day (Ann) >= (Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth)


Am I missing something?
 
Why are you using the elaborate formula for {Trips.tdate}--isn't that in the same format? Just wrap it in date(). The problem with your current formula if you must use it is that it should read:

DateVar Birth:= date(val(left({Trips.tdate}),4)),val(mid({Trips.tdate},5,2)),val(right({Trips.tdate},2))));

-LB
 
Nevermind...I was apparently using a variation of the formula instead of this one:

WhileReadingRecords;
DateVar Birth:= date({Customers.dob}); // Replace this with your field for Date Of Birth
DateVar Ann := date({Trips.tdate}); // 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


Once I used your suggestions with the correct formula, it worked perfectly.

Thank you again for your help. You're always quick to respond and always help me out.

Thanks again LB...

Chad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top