Have you ever missed records while filtering dates in SQL?
Imagine your manager asks you to prepare a report showing all orders placed on 7 November 2026.
Your "orders" table contains both dates and timestamps, such as "2026-11-07 14:30:00".
You decide to use BETWEEN to filter the records.
But will your query return all orders placed on that day?
Let's look at the data.
orders
| order_id | order_date | amount |
|---|---|---|
| 101 | 2026-11-07 09:30:00 | 5000 |
| 102 | 2026-11-07 14:45:00 | 3000 |
| 103 | 2026-11-07 22:15:00 | 7000 |
| 104 | 2026-11-08 08:00:00 | 4000 |
Your Challenge
Write an SQL query to:
- Retrieve all orders placed on 7 November 2026.
- Include orders placed at any time during that day.
- Exclude orders placed on 8 November 2026.
- Use a date range condition to filter the records.
Think before you scroll!
The SQL Solution
SELECT
order_id,
order_date,
amount
FROM orders
WHERE order_date >= '2026-11-07'
AND order_date < '2026-11-08';
Expected Output
| order_id | order_date | amount |
|---|---|---|
| 101 | 2026-11-07 09:30:00 | 5000 |
| 102 | 2026-11-07 14:45:00 | 3000 |
| 103 | 2026-11-07 22:15:00 | 7000 |
Why is this useful?
Date filtering is common in real-world SQL projects.
You can use this approach to find:
- Daily sales transactions
- Customer registrations
- Employee attendance records
- Orders placed during a specific date
- Daily revenue for business reports
One Important Thing to Remember
BETWEEN includes both boundary values.
When you write:
WHERE order_date BETWEEN '2026-11-07'
AND '2026-11-07'
Many SQL databases interpret the ending date as midnight at the start of that day when comparing against a timestamp.
As a result, orders placed later that day may be missed.
Using ">= start_date AND < next_date" is a reliable approach for timestamp-based date filtering.
Your Turn: Can you solve the same problem using BETWEEN without missing any orders?
Share your SQL query in the comments. Let's learn together!



