Answer the question
In order to leave comments, you need to log in
How can this be. Different result for "less than or equal to" and "BETWEEN" for the same date?
Good afternoon. There is a MySQL database, there is a query, in part of which is this:
AND `info`.`created` <= STR_TO_DATE('2021-04-14 23:59:59', '%Y-%m-%d %H:%i:%s')
AND `info`.`created` BETWEEN STR_TO_DATE('2021-04-14 00:00:00', '%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('2021-04-14 23:59:59', '%Y-%m-%d %H:%i:%s')
AND DATE_FORMAT(`info`.`created`, '%Y-%d-%m') <= '2021-04-14' -- выводит 10 строк где `info`.`created` = 2021-04-14
AND DATE_FORMAT(`info`.`created`, '%Y-%d-%m') = '2021-04-14' -- выводит 13 строк где `info`.`created` = 2021-04-14
Answer the question
In order to leave comments, you need to log in
Here is the link:
https://www.techonthenet.com/mysql/between.php
Where it says
When using the MySQL BETWEEN Condition with dates, be sure to use the CAST function to explicitly convert the values to dates.
I can't say exactly what is the difference between
STR_TO_DATE('2021-04-14 23:59:59', '%Y-%m-%d %H:%i:%s')
and
CAST('2014-02 -01' AS DATE)
but maybe it is.
In addition, perhaps it is not the date that plays the role, but the time.
2021-04-14 < 2021-04-14 11:46:23
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question