return age in years and months from date of birth 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?

Like this:

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
You can do it with variables, like this:

SELECT
  user_id,
  year(@fecha:=from_days(datediff(now(), user_birthdate))) as years,
  month(@fecha) as months


But have caution with the execution order. If you assign the value in SELECT don't expect same value in WHERE part.