MySQL query per month

I have a table with the following fields

id (int)
name (varchar)
dob (datetime)

Now I need a query that can match the month and year at the same time

Now i'm using

select * from users where month(dob)='12' and year(dob)='2010'

I do not want to use month () and year (), can this be done in a single thing?

Help rate

thank

+3
source share
2 answers

It can be expressed at your request, but I do not think it will be more effective.

where dob >= '2010-12-01' and dob <= '2010-12-31 23:59:59'

or

where '201012' = date_format(dob,'%Y%m')
+5
source
select * from users where dob >= '2010-12-01' and dob < '2011-01-01'
+1
source

Source: https://habr.com/ru/post/1779544/


All Articles