I have a table with following fields
id (int) name (varchar) dob (datetime)
Now I need a query that can match month and year at same time
What I am using right now is
select * from users where month(dob)='12' and year(dob)='2010'
I don't want to use month() and year(), can it be done in single thing?
It can be expressed as you request, but I don't think it would be any more efficient.
where dob >= '2010-12-01' and dob <= '2010-12-31 23:59:59'
where '201012' = date_format(dob,'%Y%m')Answer2: