Using MySQL, I return the age in years and months as separate fields in a query.
This may well be a premature optimization but the duplicate calls to datediff and from_days in this query are upsetting.
Is it possible to get the from_days(datediff(now(), user_birthdate)) factored into a single call without a nested query?
SELECT user_id, year(from_days(datediff(now(), user_birthdate))) as years, month(from_days(datediff(now(), user_birthdate))) as months
or... would a nested query be a win over this current query?
SELECT user_id, YEAR(age) AS years, MONTH(age) AS months FROM (SELECT *, FROM_DAYS(TO_DAYS(NOW()) - TO_DAYS(user_birthdate)) AS age FROM users) AS users_temp
If someone can give me some hints about the best way to test the relative performance of these two methods empirically, that would be useful too