1
In my application I have a query by date, below is an excerpt from the script
tblacesso.HorarioSaida BETWEEN '2017-06-17 00:00:00' AND '2017-06-17 23:59:59'
But it is not selecting the data of the day in question, below is an image in the data in the database.
If I change to: tblacesso.HorarioSaida BETWEEN '2017-06-16 00:00:00' AND '2017-06-16 23:59:59'
appears some data, but appears until the day 17 also.
The whole query is:
$sql = "SELECT tblacesso.Codigo, tblfrota.Codigo AS CodigoFrota, tblpessoa.NomeCompleto, tbldestino.Descricao, tblacesso.KMSaida, tblacesso.KMEntrada, "
. "DATE_FORMAT(HorarioSaida, '%d/%m/%Y %H:%i:%s') AS 'DataSaida', "
. "DATE_FORMAT(HorarioEntrada, '%d/%m/%Y %H:%i:%s') AS 'DataEntrada' "
. "FROM tblacesso "
. "INNER JOIN tblfrota ON(tblacesso.FrotaID = tblfrota.Codigo) "
. "INNER JOIN tblpessoa ON(tblacesso.MotoristaID = tblpessoa.Codigo) "
. "INNER JOIN tbldestino ON(tblacesso.DestinoID = tbldestino.Codigo)"
. "WHERE tblacesso.Status = false AND DATE(tblacesso.HorarioSaida) BETWEEN '".$data. " 00:00:00' AND '" .$data." 23:59:59'";
Still not working.
– user31040
What kind of your field?
– Roberto de Campos
The field is Datetime
– user31040
So it should work, so put the whole query to see if the problem is not another.
– Roberto de Campos
tblacesso WHERE Horariosaida >= '2017-06-16 00:00:00' AND Horariosaida <= '2017-06-16 23:59:59'
– user60252