The factor is that you record datetime
and compares with date
a solution is to use the function date()
of the bank as follows:
SELECT * FROM vendas WHERE date(feita_em) >= '2019-10-10'
AND date(feita_em) <= '2019-10-11'
It will already solve because regardless of time the date has it will only consider the date.
Another way would be to tailor the time in this comparison where the initial date begins to 00:00:00
and the end date of the 23:59:59
ai being unnecessary to convert the date stored in the bank, example:
SELECT * FROM vendas WHERE feita_em >= '2019-10-10 00:00:00'
AND feita_em <= '2019-10-11 23:59:59'
With BETWEEN and the adjustment that has already been explained:
SELECT * FROM vendas WHERE date(feita_em) BETWEEN '2019-10-10' AND '2019-10-11' // ou
SELECT * FROM vendas WHERE feita_em BETWEEN '2019-10-10 00:00:00' AND '2019-10-11 23:59:59'
Question nothing to do, in this situation which would be the most effective ?
– ScrapBench
@Scrapbench your question is good yes, would have to analyze the two
SQL
One goes through conversion to the other won’t depend on the scenario. Sincerity has to check the plan of execution of the two, for little information I think (achismo, no test) that has no significant differences– novic