Filtering with Range — Numeric and Date Range Queries
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Filtering with Range. We cover key concepts, practical examples, and best practices to help you master this topic.
Range filtering lets clients filter records within numeric or date ranges using min/max or before/after parameter conventions for bounded data queries.
Request Format
GET /api/products?price_min=10&price_max=100
GET /api/orders?created_after=2026-01-01&created_before=2026-06-28
GET /api/users?age_gte=18&age_lte=65
Implementation
app.get("/api/products", async (req, res) => {
const { price_min, price_max } = req.query;
const conditions = [];
const params = [];
let idx = 1;
if (price_min) {
conditions.push(`price >= $${idx++}`);
params.push(parseFloat(price_min));
}
if (price_max) {
conditions.push(`price <= $${idx++}`);
params.push(parseFloat(price_max));
}
const where = conditions.length
? `WHERE ${conditions.join(" AND ")}`
: "";
const result = await db.query(`SELECT * FROM products ${where}`, params);
res.json({ data: result.rows });
});
Naming Conventions
# Common range parameter conventions:
# Closed range:
price_min / price_max
# Suffix-based:
price_gte / price_lte # greater than or equal / less than or equal
price_gt / price_lt # strict greater than / less than
Common Mistakes
- No boundary validation — Accepting illogical ranges like price_min > price_max.
- Inclusive vs exclusive confusion — Not documenting whether ranges are inclusive.
- Date format ambiguity — Not specifying the date format (ISO 8601 recommended).
Practice Questions
- How do you filter records within a price range?
- What naming conventions work for range parameters?
- Why validate range boundaries server-side?
Challenge
Implement range filtering for a hotel booking API with price range, date range (check-in to check-out), and guest count range.
What's Next
In the next lesson, you will learn text search filtering.
← Previous
Filtering with Exact Match — Precise Field Value Filtering
Next →
Filtering with Text Search — Full-Text and Partial Match
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro