MySQL retrieve results between 2 dates without time factor doesn't output results of exact date

Cary Bondoc

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

  1. 2012-05-02
  2. 2012-05-04

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.

Paul Maxwell
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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL query results with weekday between 2 dates

From Dev

MySQL changing system date doesn't have the expected results

From Dev

My query to retrieve events between 2 search dates does not return any results, why?

From Dev

The results of search without gridview doesn't displaying in Yii2

From Dev

Why doesn't JSFiddle output results for this code

From Dev

Dates sort mysql results

From Dev

mysql WHERE BETWEEN by date return incorrect results?

From Dev

MATCH ... AGAINST doesn't come up with exact results

From Dev

How to get results from the query if the selected date is between two dates?

From Dev

MySQL query doesn't show results properly

From Dev

Why doesn't NOT IN always retrieve the same results as MINUS in Oracle?

From Dev

MySQL current date between 2 set dates

From Dev

Complicated query to get results between 2 dates / datetimes

From Dev

MYSQL: Query data between two dates using date_format doesn't work

From Dev

MySQL results by date

From Dev

How to send MySQL query results to outfile and standard output at the same time?

From Dev

How to send MySQL query results to outfile and standard output at the same time?

From Dev

Discrepancy between results of EXACT function and Conditional Formatting

From Dev

ToString() of copied NameValueCollection doesn't output desired results

From Dev

Simple Python Multiprocessing function in Spyder doesn't output results

From Dev

Simple code doesn't output all required results

From Dev

MYSQL dont display results where date and time has passed

From Dev

Single MySQL query summing results between a date and having count

From Dev

queryForRowSet doesn't return results with null in optional date parameter

From Dev

MySQL: Group By multiple columns not giving exact results

From Dev

MYSQL between doesn't include max date

From Dev

SQL grouping results without overlapping dates

From Dev

Comparison between dates returning odd results

From Dev

Generating results based on gap between dates for a theatre

Related Related

  1. 1

    MySQL query results with weekday between 2 dates

  2. 2

    MySQL changing system date doesn't have the expected results

  3. 3

    My query to retrieve events between 2 search dates does not return any results, why?

  4. 4

    The results of search without gridview doesn't displaying in Yii2

  5. 5

    Why doesn't JSFiddle output results for this code

  6. 6

    Dates sort mysql results

  7. 7

    mysql WHERE BETWEEN by date return incorrect results?

  8. 8

    MATCH ... AGAINST doesn't come up with exact results

  9. 9

    How to get results from the query if the selected date is between two dates?

  10. 10

    MySQL query doesn't show results properly

  11. 11

    Why doesn't NOT IN always retrieve the same results as MINUS in Oracle?

  12. 12

    MySQL current date between 2 set dates

  13. 13

    Complicated query to get results between 2 dates / datetimes

  14. 14

    MYSQL: Query data between two dates using date_format doesn't work

  15. 15

    MySQL results by date

  16. 16

    How to send MySQL query results to outfile and standard output at the same time?

  17. 17

    How to send MySQL query results to outfile and standard output at the same time?

  18. 18

    Discrepancy between results of EXACT function and Conditional Formatting

  19. 19

    ToString() of copied NameValueCollection doesn't output desired results

  20. 20

    Simple Python Multiprocessing function in Spyder doesn't output results

  21. 21

    Simple code doesn't output all required results

  22. 22

    MYSQL dont display results where date and time has passed

  23. 23

    Single MySQL query summing results between a date and having count

  24. 24

    queryForRowSet doesn't return results with null in optional date parameter

  25. 25

    MySQL: Group By multiple columns not giving exact results

  26. 26

    MYSQL between doesn't include max date

  27. 27

    SQL grouping results without overlapping dates

  28. 28

    Comparison between dates returning odd results

  29. 29

    Generating results based on gap between dates for a theatre

HotTag

Archive