I have the following Oracle query
SELECT *
FROM table
WHERE date_opened
BETWEEN ((TO_DATE('2011-08-01', 'yyyy-mm-dd') - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400))
AND ((TO_DATE('2011-08-31', 'yyyy-mm-dd') - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400))
that nearly works but it doesn’t include the dates records that are dated 2011-08-31. Any ideas? It has probably got something to do with how I am converting my date strings…
UPDATE: I really should have said that the date is actually a UNIX timestamp. That is why I am using the 86400 and 01-JAN-1970
Thank you 🙂
If the upper bound of an interval is not included in your results, then it’s likely that you’re building an “exclusive” filter with respect to the upper bound. So just add one day to the upper bound. I.e.
In Oracle,
+1will add one day when used in date time arithmetic.Note:
BETWEEN .. ANDcreates an inclusive filter, as Ollie stated, but your arithmetic may change that behaviour by transforming things to seconds