SELECT mysqli error per date

Asked

Viewed 36 times

-1

Good morning guys, all right? Here’s the problem. I put for the digital user the initial and final date to search for a certain result in the database. The Code is this:

$query = mysqli_query($conexao, "SELECT * FROM pontocolaborador WHERE cpfColaborador = '$aba' AND dataPonto >= '$inicial' AND dataPonto <= '$final' ORDER BY dataPonto ASC");

However, when I type for example: Initial date 01/10/2019 to 31/10/2019, it ends up also pulling the date 01/11/2019 to 04/11/2019 that in the case is between the digital period. However, I did not pull up the date of month 10, but rather the date of month 11. Question: Is there any possibility to bar this? Thank you!!!

1 answer

0


Add the SQL DATE function to the date fields, especially if the date fields are set to DATETIME.

Code:

$SQL = "SELECT * FROM pontocolaborador WHERE cpfColaborador = '$aba' AND DATE(dataPonto) >= '{$inicial}' AND DATE(dataPonto) <= '{$final}' ORDER BY dataPonto ASC"

$query = mysqli_query($conexao, $SQL);

One tip I suggest to you is to build your query and test in your DBMS to make sure it works and then move on to PHP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.