Thanks for all your help guys, in the end I could only get this one working:
Code:
SELECT
(year(current_date) - year( birthday_search )) AS age,
username
FROM
user
WHERE
birthday_search <> '0000-00-00'
I unfortunately couldn't get rudy's to work. I changed user_name to username and yourtable to user:
Code:
select username
, birthday_search
, year(current_date)
- year(birthday_search)
- case when month(current_date)
> month(birthday_search)
then 0
when month(current_date)
< month(birthday_search)
then 1
when day(current_date)
< day(birthday_search)
then 1
else 0
end AS age
from user
where year(current_date)
- year(birthday_search)
- case when month(current_date)
> month(birthday_search)
then 0
when month(current_date)
< month(birthday_search)
then 1
when day(current_date)
< day(birthday_search)
then 1
else 0
end >= 18
But I got this SQL error:
Code:
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(current_date)
< day(birthday_search)
Bookmarks