Alex A
asked on
T-SQL: calculating person age
One table column has Date of Birth.
I have to calculate person's age in years, for example 1.23 , 8.35 , 37.36 etc. in another column.
Any thoughts on this?
I have to calculate person's age in years, for example 1.23 , 8.35 , 37.36 etc. in another column.
Any thoughts on this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I like it, but I see a couple of problems, such as:
Illustrating the first, consider this example:
Open in new window
This returns 1.00 and 1.00, respectively, yet most people would agree that this person is not yet a year old. Using only two digits for the decimal portion is not precise enough. Using decimal(10, 4) instead would remedy that.
Now consider how using 365.25 can understate the age in some edge cases. (I am adopting the more precise decimal(10, 4) here.)
Open in new window
The "365" formula returns 1.0000, and the "365.25" formula returns 0.9993, but everyone would agree that such a person should be counted as one year old.
:)
Patrick