MySQL DATE_FORMAT with "WHERE"

Hi,
Here are 2 query strings:

$q2="SELECT *, DATE_FORMAT(users.dob, ‘%X’) as age FROM users LEFT JOIN userinfo ON users.ID=userinfo.userID
WHERE age < ‘$max’ AND age > ‘$min’ ";

$q="SELECT DATE_FORMAT(users.dob, ‘%X’) as age FROM users
WHERE age < ‘$max’ AND age > ‘$min’ ";

dob is date of birth. which is stored in this format: 2006-12-31

DATE_FORMAT(users.dob, ‘%X’) gives me 2006
I want to SELECT all the profiles who were born between 1950 and 2000 for example…

Originally i wanted to use $q2, but i got this error:

Unknown column ‘age’ in ‘where clause’

I thought that the JOIN might have been the problem, so i simplified it.
At this point, it looks like I cant format a column and the use is to filter my SELECT with WHERE.
can someone help me?

I’ve been doing some research on the problem but i can’t find anything