In the DB table I have a "day" column type "date" saving "yyyy-mm-dd", I'm trying to make a query that returns me the current month, I've tried it in several ways and nothing.
<?php session_start();
date_default_timezone_set('America/Sao_Paulo');
$d = date('d');
$m = date('m');
$y = date('Y');
$query_cx = "SELECT dia FROM caixa WHERE MONTH(data)='$m' ORDER BY id DESC";
$result_cx = mysqli_query($conectar, $query_cx);
while ($linhas_cx = mysqli_fetch_assoc($result_cx)){
echo "$linhas_cx['valor'];
}
?>
the second part is doubtful, thinking that the year is ending and that this query will always return me the current month;
1- Will this query end up returning me the current Month and the same month of the previous year?
2- How would I search for some previous Month, if the year will be different?