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

date less than 30 days from another date

Status
Not open for further replies.

sheriberi

Technical User
Mar 13, 2013
7
US
I am trying to look at patients with a test date within 30 days before their procedure date. So if the test was 20 days before the procedure, they count as Yes. But if the test was 31 days (or more) before the procedure date, they don't count (No). What I am using is calculating correctly sometimes, but not all the time and I don't understand it.

if ({TEST.DATE}) > DateAdd('d',-30, {PROCEDURE.DATE})
then "Yes"
ELSE "No"

 
I got my answer on another site's board and it works beautifully if anyone ever needs to do same:

You may need to ensure the testdate is before the procedure date

if ({TEST.DATE}) >= DateAdd('d',-30, {PROCEDURE.DATE}) AND {TEST.DATE} <= {PROCEDURE.DATE}
then "Yes"
ELSE "No
 
When you are dealing with dates and adding/subtracting whole days, it is not necessary to use DateAdd. It could be simplified further using IN rather than using separate < and >. Your formula could therefore be simplified as follows:

Code:
If 	{TEST.DATE} in [{PROCEDURE.DATE} - 30 to {PROCEDURE.DATE}]
Then 	"Yes"
Else 	"No"

Hope this helps.

Cheers
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top