October 5, 2009 at 3:20 am
The problem is that I need to have a fractional age in two decimals. I need that to calculate a precise decimal average age and exact decimal risc score of large groups of patients.
Right now I use the following calculation:
DATEDIFF(DAY, birthdate, operationdate)/365.2422
The division by 365.2422 takes leap years into account. I know that it's not perfect. For instance it gives an age of 16.999678 instead of 17.0 when the birth date is May 23 1992 and the operation date is May 23 2009. But I wonder if it's even possible to get an exact .0 age in every case like this when you calculate a fractional age?
I also found out that with higher ages 365.25 gives better results to divide with. So it seems this number has a relation with the age.
Furthermore the age that we round in two decimals sometimes shows differences with fractional ages that hospitals deliver to us and we need to inform the hospitals of that. For that reason I need to be absolutely sure that this is the best way to calculate a fractional age. Thanks in advance.
October 5, 2009 at 6:08 am
Have you tried rounding?
select round(DATEDIFF(DAY, 'May 23 1992', 'May 23 2009')/365.2422,2)
select round(DATEDIFF(DAY, 'May 23 1992', 'May 25 2009')/365.2422,2)
select round(DATEDIFF(DAY, 'May 23 1992', 'Nov 23 2009')/365.2422,2)
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
October 5, 2009 at 7:18 am
Yes, but which calculation is best? Divide by 365.25 or 365.2422? I think 365.25 is best considering the average age of our patients is around 60. With an age of 100, 365.25 results in an exact age of 100.0.
The problem could be border cases when I round it at 2 decimals. For instance let's say that I get a result of 65.445 instead of 65.444. The first one results in 65.45 and the second one in 65.44. Also border cases like 69.99 and 70.00. When you FLOOR the age you get different ages.
Is there a better way to get a fractional age?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply