Oracle SQL Date Filters for Monthly Reports
Oracle SQL · Reporting
Include the last daydown to the last second.
A report for November should include records from November 30 at 11:59 p.m. Here’s how I write date filters in Oracle SQL so those rows make it into the report.
Why records disappear
Oracle’s DATE type stores a date and a time through the second. The literal DATE '2026-11-30' represents November 30 at midnight. If you use it as the upper boundary with <=, a case opened later that day falls outside the range.
Use the next day as the cutoff
Include the start of November with >= and stop before December 1 with <. This is a half-open range. The following self-contained query runs on three illustrative rows.
WITH demo_cases (case_id, opened_at) AS (
SELECT 101, DATE '2026-11-01' FROM dual
UNION ALL
SELECT 102, DATE '2026-12-01' - 1 / 86400 FROM dual
UNION ALL
SELECT 103, DATE '2026-12-01' FROM dual
)
SELECT case_id, opened_at
FROM demo_cases
WHERE opened_at >= DATE '2026-11-01'
AND opened_at < DATE '2026-12-01'
ORDER BY opened_at;
Expected result. Cases 101 and 102 are included. Case 103 starts the next reporting period.
Test the boundaries
| Case opened at | In November report? |
|---|---|
| Yes | |
| Yes | |
| No |
For a report with user-selected dates, pass the inclusive start and exclusive end as bind variables of the appropriate date or timestamp type. Test these boundary cases against a representative dataset before release.
Read more in the Oracle SQL Language Reference on date literals.