Filter records by date

1

My code is not working what might be wrong? In the database the date is with Date / Time as datetime , follow the code:

<?php       
    $query = $mysql->query("SELECT * FROM c_clientes WHERE cliente_data_cadastro 
               BETWEEN '2018-04-07 12:53:14' AND '2018-05-07 12:53:14'");

    echo "<center>". mysqli_num_rows($query). " Registros</center>";

    while($row = $query->fetch_array())
    {       
        echo $row['cliente_data_cadastro']." - "
             .$row['cliente_nome']." "
             .$row['cliente_sobrenome']."<br>"; 

    }       
?>
    
asked by anonymous 07.05.2018 / 16:22

1 answer

2

If you do not need to compare hours, use the TRUNC function:

<?php       
    $query = $mysql->query("SELECT * FROM c_clientes WHERE trunc(cliente_data_cadastro) 
               BETWEEN '2018-04-07' AND '2018-05-07'");

    echo "<center>". mysqli_num_rows($query). " Registros</center>";

    while($row = $query->fetch_array())
    {       
        echo $row['cliente_data_cadastro']." - "
             .$row['cliente_nome']." "
             .$row['cliente_sobrenome']."<br>"; 

    }       
?>
    
07.05.2018 / 16:30