Jump to content

Avg of date


tobeyt23

Recommended Posts

I am trying to get the average age based off the date of birth (mm/dd/yyyy) this is what I have but keep getting 51. Sure this is correct any suggestions?

 

SELECT FLOOR(AVG(TO_DAYS(NOW())-TO_DAYS(CONCAT(SUBSTR(user_profiles.dob, 7,4),'-',SUBSTR(user_profiles.dob, 1, 2),'-',SUBSTR(user_profiles.dob, 4, 2))))/365.242199) FROM user_profiles WHERE user_profiles.dob !=''

Link to comment
https://forums.phpfreaks.com/topic/231434-avg-of-date/
Share on other sites

  • 2 months later...

Think this does it:

 

SELECT ROUND((YEAR(NOW()) - AVG(STR_TO_DATE(user_profiles.dob,'%m/%d/%Y')))) FROM user_profiles WHERE user_profiles.dob != '' AND YEAR(STR_TO_DATE(user_profiles.dob,'%m/%d/%Y')) != YEAR(NOW()) AND YEAR(STR_TO_DATE(user_profiles.dob,'%m/%d/%Y')) != (YEAR(NOW())-1)

Link to comment
https://forums.phpfreaks.com/topic/231434-avg-of-date/#findComment-1227448
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.