dateField
const dateField: (input) => KnexFieldSpec;Defined in: filters/knex.ts:41
Allow-list a public field as a date filter over a timestamp column, named by a column
string ("created_at" or "posts.created_at", quoted per part; anything else throws). A
date preset needs the resolveDate you pass to buildWhereSql, and becomes a half-open
[start, end) window.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ column: string; } |
input.column |
string |
Returns
Section titled “Returns”Example
Section titled “Example”import { buildWhereSql, dateField } from "@xtandard/lib/filters/knex";
// Your resolver turns the preset into instant bounds (this one is hard-coded).const resolveDate = () => ({ start: new Date("2026-01-01T00:00:00Z"), end: new Date("2026-02-01T00:00:00Z") });buildWhereSql({ spec: { createdAt: dateField({ column: "posts.created_at" }) }, filters: [{ field: "createdAt", filter: { kind: "date", operator: "is", unit: "month", timeZone: "UTC", anchor: "2026-01-15T00:00:00" } }], resolveDate,})?.sql;// → '("posts"."created_at" >= ? AND "posts"."created_at" < ?)'