Format Mysql data

Asked

Viewed 55 times

1

I have a problem when passing a date to a select. Using the form below, select me returns the data normally:

SELECT H.* FROM HORARIOS H
                     WHERE NOT EXISTS (
                           SELECT * FROM RESERVAS R
                                WHERE H.COD BETWEEN R.COD_HORA_SAIDA AND
                                      R.COD_HORA_PREVISTA-1 AND
                                      R.COD_VEICULO = 1 AND
                                      R.DATA_SAIDA = '2015-11-26')
                                ORDER BY H.COD;

But, if I try to pass to the d-m-a format as below, it does not correctly return the data.

SELECT H.* FROM HORARIOS H
                     WHERE NOT EXISTS (
                           SELECT * FROM RESERVAS R
                                WHERE H.COD BETWEEN R.COD_HORA_SAIDA AND
                                      R.COD_HORA_PREVISTA-1 AND
                                      R.COD_VEICULO = 1 AND
                                      DATE_FORMAT(R.DATA_SAIDA, '%d-%m-%Y') = '26-11-2015')
                                ORDER BY H.COD;

Someone could tell me why he won’t accept it this way?

  • 1

    It would not only be DATE_FORMAT(R.DATA_SAIDA,'%m-%d-%Y') = 26-11-2015' so that the latter ) ?

  • the latter is the parameter that comes from PHP. It comes in this dd-mm-yyyy format

  • In the first example this R.DATA_SAIDA, IN THE SECOND DATA_SAIDA ONLY, this is certain ?

  • It was a typo, I fixed it.

  • I’m glad it worked out!

No answers

Browser other questions tagged

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