How to filter only the date of a field that has a date and time set?

1

I need to create a select in MySQL to filter the month in a table, but the field where the date is set, has also set the time, like this: [2017-02-04 10:00:00]

How do I filter only the date of this field by considering only the month and disregarding other values such as day, year, and time?

    
asked by anonymous 28.08.2017 / 19:58

2 answers

3

SQL - to return only the month

select MONTH(Nome_coluna) from Nome_tabela

To return the date

select cast(Nome_coluna as date) from Nome_tabela

And return the date considering only the month

select cast(Nome_coluna as date) from Nome_tabela WHERE MONTH(Nome_coluna) = num_mes

being num_mes a number of 1 a 12

    
28.08.2017 / 21:30
0

Use strtotime() and then return the format you want to return. For example date("m",$time) to redeem the month. See:

$dateValue = "2017-02-04 10:00:00";
$time = strtotime($dateValue);
$month = date("m",$time);

See working no ideone .

    
28.08.2017 / 20:05