Get month from datetime field mysql

0

Colleagues,

I have a table where it has the datetime () field of Mysql. I would like to get a particular month directly from the where clause. By PHP I know how to do it, but how would I do it directly through the query? I tried this way to get the records for May, but it did not work:

$mês = $_POST["MesBusca"]; // Vamos supor que seja mês de maio (05)
SELECT * FROM tabela WHERE MONTH(DataAbertura) = MONTH(".$mes."); // Tentei também com o 5

    
asked by anonymous 03.05.2017 / 20:28

1 answer

1

Well, my friend, I did not quite understand what you want; But let's see if you want to get all the records for the month of May, it would look like this:

SELECT * FROM tabela WHERE MONTH(DataAbertura) = 5;

Where 5 is the number of the month, Month () already returns an integer value does not need to convert Month (5) as you did;

Now if you want to get the month of a specific date it would look like this:

select MONTH(DataAbertura) from tabela
    
03.05.2017 / 20:54