API date input
Validate request, form, or configuration fields that carry dates as text.
Zod · Module
z.iso.date() validates strings in the YYYY-MM-DD format and rejects malformed or impossible calendar dates. Use z.date() for JavaScript Date instances.
Call z.iso.date() to create a schema for strings written as four-digit year, two-digit month, and two-digit day. Parsing accepts a valid calendar date and rejects malformed or impossible dates; use z.date() instead when the input should be a JavaScript Date instance.
z.iso.date();A Zod schema that validates ISO calendar-date strings.
import { z } from "zod";
const date = z.iso.date();
console.log(date.parse("2020-01-01"));
// date.parse("2020-1-1"); // throws
// date.parse("2020-01-32"); // throws
Creates an ISO calendar-date schema and parses a valid YYYY-MM-DD string.
Validate request, form, or configuration fields that carry dates as text.
Enforce a stable, zero-padded calendar-date representation before persistence or processing.
Keep date-only values separate from timestamps and JavaScript Date objects.
z.iso.date() returns a Zod schema that validates ISO-style calendar-date strings in YYYY-MM-DD form. Its parser accepts values such as 2020-01-01.
Follow-up: How would you validate a JavaScript Date instead? Use z.date(), because z.iso.date() is for strings.
It requires fixed-width year, month, and day components: 2020-01-01 is valid, while 2020-1-1 is not. It also rejects impossible dates such as 2020-01-32.
Follow-up: What additional distinction should an API designer make? Choose z.iso.datetime() when the value must include a date and time rather than only a calendar date.
Parsing with date.parse(value) returns the validated string when successful and throws when validation fails. The schema does not convert the string into a Date object.
Follow-up: How can a conversion be modeled? Compose an appropriate input schema with a codec or transformation when a Date object is required.
z.iso.timez.iso.datetimez.iso.durationz.date