Problem: Selecting data within a date range results in exclusion of the upper bound date due to the default midnight cutoff.
Query:
SELECT `users`.* FROM `users` WHERE created_at >= '2011-12-01' AND created_at <= '2011-12-06'
Solution:
To resolve this issue, there are several options:
SELECT users.* FROM users WHERE created_at >= '2011-12-01' AND created_at <= '2011-12-07'
SELECT users.* from users WHERE created_at >= '2011-12-01' AND created_at <= date_add('2011-12-01', INTERVAL 7 DAY)
SELECT users.* from users WHERE created_at BETWEEN('2011-12-01', date_add('2011-12-01', INTERVAL 7 DAY))
These solutions all ensure that data from the specified date range, including the upper bound date, is selected.
The above is the detailed content of How to Include the Upper Bound Date When Selecting Data Between Two Dates in MySQL?. For more information, please follow other related articles on the PHP Chinese website!