Solved

The best age computation formula

Posted on 2001-07-10
7
579 Views
Last Modified: 2010-07-27
Hi Experts,

I'm working on a report that computes patient's age.
With Crystal 8, this is not a problem because of the Datediff function but with crystal 7, I need to manipulate date fields to get the patient age.

Can anybody show me the best formula to compute the patient's age in CR7?

TIA,

zero
0
Comment
Question by:zerobro
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:jsweby
ID: 6276010
Can't you simply subtract the date of birth from today's date ("Date") and divide the result by 365.25?

J.
0
 

Author Comment

by:zerobro
ID: 6276157
Hi jsweby,

I have that before but there's a little bit of a problem:

with a patient whose birthdate is 1/3/82, using the formula you propose ((CurrentDate - {PATIENT.BIRTHDATE}) / 365.25) will generate an age of 19.52. This is correct but the thing is, I wanted to round this up. When I do so, it will become 20 which in anyway the wrong age.

When using CR8's DIFFDATE function in the formula:

DateDiff ("YYYY", {PATIENT.BIRTHDATE}, CurrentDate)

The result is 19 which is the right one I need.

Although I have CR8, due to a very valid reason, I need to use CR7 for this report.

That's basically my problem,

zero
0
 

Author Comment

by:zerobro
ID: 6276160
Hi jsweby,

I have that before but there's a little bit of a problem:

with a patient whose birthdate is 1/3/82, using the formula you propose ((CurrentDate - {PATIENT.BIRTHDATE}) / 365.25) will generate an age of 19.52. This is correct but the thing is, I wanted to round this up. When I do so, it will become 20 which in anyway the wrong age.

When using CR8's DIFFDATE function in the formula:

DateDiff ("YYYY", {PATIENT.BIRTHDATE}, CurrentDate)

The result is 19 which is the right one I need.

Although I have CR8, due to a very valid reason, I need to use CR7 for this report.

That's basically my problem,

zero
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 4

Expert Comment

by:jsweby
ID: 6276167
Don't round the age, truncate it so that you always get the whole number, never rounded. The Truncate function will do this for you.

J.
0
 

Author Comment

by:zerobro
ID: 6276336
what do you mean truncate?? convert this to a text and parse the needed portion?

please show me how to do this by example.

zero
0
 
LVL 4

Accepted Solution

by:
jsweby earned 30 total points
ID: 6276346
No, truncate is a mathmatical function that takes a decimal number and returns the number rounded down to the nearest integer, so that 19.52 becomes 19, 19.99 also becomes 19:

Age := Truncate((CurrentDate - {PATIENT.BIRTHDATE}) / 365.25)

J.
0
 

Author Comment

by:zerobro
ID: 6276392
Ok, I got it...thanks for the time...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question