The second date reference in the BETWEEN syntax was supposed to be magically considered the βend of the day,β but this is not true .
i.e. this was expected:
SELECT * FROM Cases
WHERE created_at BETWEEN the beginning of '2013-05-01' AND the end of '2013-05-01'
but what really happens is:
SELECT * FROM Cases
WHERE created_at BETWEEN '2013-05-01 00: 00: 00 + 00000 ' AND '2013-05-01 00: 00: 00 + 00000 '
This becomes equivalent:
SELECT * FROM Cases WHERE created_at = '2013-05-01 00: 00: 00 + 00000 '
The problem is one of the BETWEEN views / expectations that makes BOTH include a lower value and higher values ββin the range, but doesnβt magically create enter βstartβ or βendβ.
BETWEEN should be avoided when filtering by date ranges.
Always use >= AND < instead
SELECT * FROM Cases
WHERE (created_at > = '20130501' AND created_at < '20130502')
parentheses are optional here, but may make a difference in more complex queries.
Used_By_Already 04 Oct '14 at 7:50 2014-10-04 07:50
source share