rony rony - 24 days ago 8
MySQL Question

How to select a specific month and year?

I want to select november 2015 and november 2016. Is there any function or something?

I can get october 2016 by using this-


WHERE YEAR(A_Date)= YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND
MONTH(A_Date)= MONTH(CURRENT_DATE - INTERVAL 1 MONTH)


is there any similar way to get november 2016 and november 2015?

Answer

Try this:

WHERE EXTRACT(MONTH FROM A_Date)='November' 
AND EXTRACT(YEAR FROM A_Date) IN ('2015', '2016') 

OR

WHERE DATE_FORMAT(A_Date,'%Y-%m') = CONCAT(YEAR(CURDATE())-1,'-11') 
AND DATE_FORMAT(A_Date,'%Y-%m') = CONCAT(YEAR(CURDATE()),'-11')