Reputation: 15960
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?
Help appreciated
Thanks
Upvotes: 3
Views: 8765
Reputation: 57784
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'
or
where '201012' = date_format(dob,'%Y%m')
Upvotes: 5
Reputation: 30131
select * from users where dob >= '2010-12-01' and dob < '2011-01-01'
Upvotes: 1