![]() |
Query question - PLEASE HELP!!!
I really need a hack that displays the average age. Currently I am using this plugin:
PHP Code:
Andreas/KirbyDE had given me this query instead that is supposed to be more accurate: [sql] SELECT ROUND(AVG(YEAR(NOW())-YEAR(birthday_search) - (MONTH(NOW()) < MONTH(birthday_search)) - (MONTH(NOW()) = MONTH(birthday_search) AND DAY(NOW()) < DAY(birthday_search)))) AS avgage FROM " . TABLE_PREFIX . "user WHERE YEAR(birthday_search)>0 [/sql] but it gives a database error: Code:
Database error in vBulletin 3.5.0: |
try that query
[sql] SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365 AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
Thanks so much but I still get a db error... :(
Database error in vBulletin 3.5.0: Code:
Invalid SQL: PHP Code:
|
Add a ')' in front of the AS avgage.
|
Code:
Database error in vBulletin 3.5.0: I have started to think that it will never work out... :( :( :( |
it's just a problem with brackets ;)
[sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW()) / 365))) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
Now there is no database error (woo hoo!! :D) but...
Average Age: -150 :( |
very young users you have ;)
my fault, try that: [sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365)) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
It looks correct, thanks so much!!!!!! :D :D :D
Another question, not so urgent, answer if and when you have time... How can I make it to display 2 decimals? :) Thanks again! Also, do you allow me to release this as a modification? Others may need it too. Of course, I'll include the appropriate credits :) |
glad we could solve it :)
2 decimals are very easy: [sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365), 2) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] feel free to release it |
All times are GMT. The time now is 01:45 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|