Error query by date

Asked

Viewed 49 times

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.inserir a descrição da imagem aqui

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'";

3 answers

1


tblacesso WHERE HorarioSaida >= '2017-06-16 00:00:00' AND HorarioSaida <= '2017-06-16 23:59:59'

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

0

Try to do so:

DATE(tblacesso.HorarioSaida) = '2017-06-17'
  • Still not working.

  • What kind of your field?

  • The field is Datetime

  • So it should work, so put the whole query to see if the problem is not another.

  • tblacesso WHERE Horariosaida >= '2017-06-16 00:00:00' AND Horariosaida <= '2017-06-16 23:59:59'

0

Try it this way:

tblacesso.HorarioSaida >= '2017-06-17 00:00:00' AND tblacesso.HorarioSaida <= '2017-06-17 23:59:59'

Browser other questions tagged

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