# MySQL DATE\_FORMAT with "WHERE"

**URL:** <https://forum.kirupa.com/t/mysql-date-format-with-where/175020>\
**Category:** programming\
**Created:** [January 11, 2006, 3:58am UTC](https://forum.kirupa.com/t/mysql-date-format-with-where/175020 "2006-01-11T03:58:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![StarXploser](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/starxploser/32/875_2.png) [@StarXploser](https://forum.kirupa.com/u/StarXploser)\
**Post date:** [January 11, 2006, 3:58am UTC](https://forum.kirupa.com/t/mysql-date-format-with-where/175020/1 "2006-01-11T03:58:27Z")

</div>

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
