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. |