DateTime Filters
Filter operators for datetime scalars
Operators
| Operator | Description |
|---|---|
equals |
Exact match |
not |
Not equal |
in |
Match any in array |
notIn |
Match none in array |
lt |
Before (exclusive) |
lte |
Before or at (inclusive) |
gt |
After (exclusive) |
gte |
After or at (inclusive) |
equals, not, in, and notIn work the same on every scalar type — see Filtering.
Input Formats
Accept Date objects or ISO strings:
// Date object
where: { createdAt: { gte: new Date() } }
// ISO string
where: { createdAt: { gte: "2024-01-01T00:00:00.000Z" } }
Comparisons
// Before
where: { createdAt: { lt: new Date() } }
// Before or at
where: { createdAt: { lte: new Date("2024-12-31") } }
// After
where: { updatedAt: { gt: new Date("2024-01-01") } }
// After or at
where: { publishedAt: { gte: new Date("2024-01-01") } }
Date Ranges
// Between dates (inclusive)
where: {
createdAt: {
gte: new Date("2024-01-01"),
lte: new Date("2024-12-31"),
},
}
// Last 7 days
where: {
createdAt: {
gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
},
}
// This year
where: {
createdAt: {
gte: new Date(new Date().getFullYear(), 0, 1),
lt: new Date(new Date().getFullYear() + 1, 0, 1),
},
}
Examples
Last Login Filter
async function getInactiveUsers(days = 30) {
const threshold = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
return client.user.findMany({
where: {
OR: [
{ lastLoginAt: null },
{ lastLoginAt: { lt: threshold } },
],
},
});
}