Store calendar dates
A schema needs a birth date, holiday, or other calendar-only value without a time component.
Drizzle ORM · Function
Drizzle ORM’s MySQL date builder declares a calendar-date column using the SQL date type. Configure its infer mode to expose values as JavaScript Date objects or strings.
The date column builder declares a MySQL DATE column that stores a calendar date in YYYY-MM-DD form. Its infer mode controls whether Drizzle exposes the value as a JavaScript Date or as the unchanged database string.
date(config?)| Name | Type | Description |
|---|---|---|
config | object | Optional configuration selecting date or string inference mode. |
A MySQL DATE column builder.
YYYY-MM-DD representation.date from the MySQL core package and use it inside a mysqlTable definition.date gives Date values, while string leaves values as strings.import { date, mysqlTable } from "drizzle-orm/mysql-core";
export const events = mysqlTable("events", {
eventDate: date({ mode: "date" }),
});
Defines a MySQL DATE column whose inferred TypeScript value is a Date.
A schema needs a birth date, holiday, or other calendar-only value without a time component.
Application code should work with JavaScript date objects for a DATE column.
The application must preserve database date strings and handle conversion itself.
date builder represent?date() creates a MySQL DATE column for calendar dates, with values represented in YYYY-MM-DD format. The builder can infer either a JavaScript Date or a string.
Follow-up: How would you preserve the database representation? Use date({ mode: "string" }), which infers a string value.
Use date({ mode: "date" }) when the column should be inferred as a JavaScript Date. This is the date-oriented mode shown in the documentation.
Follow-up: What alternative mode is available? date({ mode: "string" }) infers the column as a string instead.
The generated SQL column type is date, and the documented database range is from 1000-01-01 through 9999-12-31. It represents a calendar date rather than a time-of-day value.
Follow-up: Which database documentation should be consulted for engine-specific details? The MySQL documentation is the referenced authority for this type.
mysqlTabletimestampdate({ mode: "date" })date({ mode: "string" })