Example 1
Return every order created during May
Orders 1 and 2 are inside May. Order 3 is exactly at the exclusive upper boundary, so it is excluded, and order 4 is before the inclusive lower boundary. This avoids depending on a final-day time such as 23:59:59.
CREATE TABLE orders (id INT, created_at TIMESTAMP);
INSERT INTO
orders (id, created_at)
VALUES
(1, '2026-05-01 00:00:00'),
(2, '2026-05-31 23:59:59'),
(3, '2026-06-01 00:00:00'),
(4, '2026-04-30 23:59:59');SELECT
id
FROM
orders
WHERE
created_at >= '2026-05-01'
AND created_at < '2026-06-01'
ORDER BY
id;| id |
|---|
| 1 |
| 2 |
The same boundary logic works across supported engines. SQLite compares ISO timestamp text correctly in this example.