Calculate Age in Years + Days using LabKey SQL?

LabKey Support Forum (Inactive)
Calculate Age in Years + Days using LabKey SQL? Ben Bimber  2013-10-23 09:18
Status: Closed
 
I'm trying to create a calculated field showing the age of subjects in a person-friendly years and days (ie. "1 years and 28 days"). LabKey SQL has functions for timestampdiff(), age(), etc. There's two pieces to this problem: rounded age in years and the remainder days. The first is easy. The second is where I have a problem. Currently I have an expression that takes the decimal portion of age-in-days divided by 365. That's pretty close, but leap years are a problem. I'm trying to figure out a better solution, but dont have any good ideas.

If I cannot find anything in SQL, my next idea is to give this a custom DisplayColumn, which renders a string using java code. The advantage is that I have a lot more ability to calculate/format my value. The drawback is that I lose some ability to sort/filter. This said, I could be smart about the raw value, and still get some reasonable behavior.

Thanks for any ideas.
 
 
jeckels responded:  2013-10-24 12:19
Ben and I talked about this. He's going forward with a Java-based renderer to get the exact calculated value he needs. The underlying column value from the database will be a decimal representation of the years (including fractional values) to give reasonable sorting and filtering behavior.

Thanks,
Josh