Displays extra values ​​for this query:

SELECT DISTINCT DATE_FORMAT(datetime, '%d.%m.%Y') AS `timedate` FROM `attendance` WHERE `personid`='1' AND DATE_FORMAT(datetime, '%d.%m.%Y') >= '01.06.2015' AND DATE_FORMAT(datetime, '%d.%m.%Y') <= '19.06.2015' ORDER BY datetime DESC 

I can not understand why.
Query result:

06/15/2015
06.11.2015
06/10/2015
06/09/2015
06/08/2015
06/01/2015
05/19/2015
05.11.2015

    2 answers 2

    Maybe because you need to specify

     DATE_FORMAT(datetime, '%d.%m.%Y')>='01.06.2015' 

    instead

     DATE_FORMAT(datetime, '%d.%m.%Y')<='01.06.2015' 

    UPD Now you are not comparing dates and lines displaying dates, but if you just need a date range then either:

     DATE([Имя поля]) >= '2015-06-01' AND DATE([Имя поля]) <= '2015-06-19' 

    or

     DATE([Имя поля]) BETWEEN '2015-06-01' AND '2015-06-19' 
    • @Regent - Question: Choosing dates from a specified range, and an obvious typo in the query - Mirdin
    • About the specified range is valid. - Regent
    • Yes, I confused the sign when the question was written. gives the correct result with the correct sign - Nikito_Os

    Piece "DATE_FORMAT (datetime, '% d.% M.% Y') <= '06/01/2015' AND DATE_FORMAT (datetime, '% d.% M.% Y') <= '19 .06.2015'" In this the piece is repeated 2 times the condition. must be changed to "DATE_FORMAT (datetime, '% d.% m.% Y') <= '19 .06.2015 '"

    • Replace two conditions with one? - Regent
    • Yes, you have it there that the date should be <= 1.06 and <= 19.06. those. condition from 1.06 is superfluous - NetWorker
    • I have nothing there. The problem with the author is that the rows as a result of the query are more than necessary. Replacing two conditions with one will make the request shorter and faster, but will not solve the problem of the author. - Regent
    • Wash if such "false" conditions go, then he puts the sign backwards, i.e. instead of <= coming> = - NetWorker
    • Yes, I confused the sign when the question was written. gives the correct result with the correct sign - Nikito_Os