This question gives us the answer on how to query between 2 dates without using time factor and it is like this
SELECT col1, col2, ..., coln
FROM order_table
WHERE order_date >= '2012-05-03'
AND order_date < '2012-05-04'
If we have the following dates
And we use this
WHERE order_date >= '2012-05-01'
AND order_date < '2012-05-04'
It will only output 2012-05-02
and it will not output 2012-05-04
Question: How can I include 2012-05-04
in my result? I don't want my user to choose 2012-05-05
just to output 2012-05-04
.
WHERE order_date >= '2012-05-01'
AND order_date < '2012-05-05'
A day has duration of 24 hours, but this can be measured in extremely small units, so 23:59:59 is NOT the final point of the duration. MySQL now does support fractions of seconds so please do not rely on 23:59:59 see http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html
The one and only always accurate method is to use LESS THAN THE NEXT DAY.
If you don't want your user to see that next day value simply take the chosen end date but add 1 day to that in your code. e.g.
WHERE order_date >= '2012-05-01'
AND order_date < date_add('2012-05-04',INTERVAL 1 DAY)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments