MYSQL fetch records from table only for a particular month -


i want fetch records mysql table in monthly wise. donot want use createdate between "2015-04-01" , "2015-04-30" nor createdate > "2015-04-01" , createdate < "2015-04-30".

i have tried :

year(createdate) = 2015 , month(createdate) = 04  #which not working. 

can tell me how write query particular month.?

it should

month(createdate) = 4

however approach

`createdate >= "2015-04-01"  , createdate <= "2015-04-30"`  

is better since utilize index, in using year or month function not use index. small data-set ok large data set overkill , query slow.

you can make dynamic as

where  createdate >=  date_format(curdate(),'%y-%m-01') , createdate <=  last_day(curdate())  

for particular month can construct query as

where  createdate >=  date_format(curdate(),'%y-04-01') , createdate <=  last_day(date_format(curdate(),'%y-04-01'))  

Comments