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!

Date Diff

Status
Not open for further replies.

luxvivens

Technical User
May 20, 2010
27
CA
I am using CR 10 and calculating a date difference to derive age of a person at the time they received a certain service.

I created the formula "Table.DateDiff" as follows:
datediff ("yyyy", {@Table.DOB},{@Table.Admit_Date})

This yields a number. For example 54 or 68, etc.

For my report, I want to limit results for people that are only 65 years of age or older when they received a service.

I do not “see” the “Table.DateDiff” field when I am in the select expert section. I must be missing a step or maybe this is something that can not be done the way I have set it up because maybe certain records have to be evaluated first. Should I try to do this in the selection formula? Should I try to approach this a different way?

I suspect I am going the long way around the block to get home.
 
You will not get an accurate age using this method. Try using Ken Hamady's formula (see his faq for a link to his website).

But the question is what is in your nested formulas? Please always show the content of your formulas.

-LB
 
Thank you LB.
Table1.field (date of procedure) is a text field with the following format “yyyymmdd”.

I made table1.field a number by doing: tonumber({Table1.field}) . Naming this formula @Table1number.field. I then converted the number to a date (naming this formula Table1date.field) by doing:

WhilePrintingRecords;
NumberVar input := {@table1number.field};
If input < 19000101 then Date (1900, 01, 01) else
Date ( Val (ToText (input, 0 , "") [1 to 4]),
Val (ToText (input, 0 , "") [5 to 6]),
Val (ToText (input, 0 , "") [7 to 8]) )

I did the same for the Table2.field (date of birth).

I then calculated the difference (naming this field @Difference) in years between the fields:
datediff ("yyyy", {@Table2Date.field},{@TableDate1.field})

This yielded the age I expected to see.

I want to use this calculated age in some selection criteria in my report. That is, I want to suppress selection of any records for patients that are below 65 years of age as identified in the @difference field. Thanks for any thoughts you have or if still need to provide additional information.
 
Remove the whileprintingrecords;

Its not required and that is preventing it being used in select expert.

Ian

 
Ian is correct--remove the whileprintingrecords, but you really should change your formula for age, too.

-LB
 
Many thanks LB and Ian ! ! !
That fixed it.
I will, as suggested, amend the formula for age.
Much appreciated.
-LV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top