• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.2 Query to find out average age of users?

Rigel Kentaurus

Well-known member
#3
And this one will give you the summary of
YEAR - NUMBER OF USERS
Code:
SELECT
    (year(now()) - dob_year) AS age,
    count(*)
FROM xf_user_profile
WHERE
    dob_year > 0 AND
    (year(now()) - dob_year) > 0
GROUP BY
    (year(now()) - dob_year)
ORDER BY age
 

Rigel Kentaurus

Well-known member
#4
If you want to get really technical. As in "that person has 25.7 years, not 26, and you are counting it as 26), you can use this query.
It is more precise

Code:
SELECT 
    AVG(DATEDIFF(NOW(), STR_TO_DATE(CONCAT(dob_day, ',' ,dob_month, ',' ,dob_year),'%d,%m,%Y')) / 365)
FROM
    xf_user_profile
WHERE
    dob_year > 0;