Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Function

z.date

z.date() creates a Zod schema for validating JavaScript Date instances. Add min() and max() to enforce lower and upper date boundaries.

How it works

z.date() creates a schema that accepts JavaScript Date instances. Use min() and max() to constrain the accepted date range, while safeParse() reports success or failure as data instead of throwing.

Syntax

z.date(params?)

Parameters

NameTypeDescription
paramsobjectOptional configuration object; the documented example uses an error callback that receives the validation issue.

Returns

A Zod schema that validates Date instances and supports date-bound refinements.

Key points

  • Use z.date() when the value should already be a JavaScript Date object.
  • A valid Date instance succeeds when passed to safeParse().
  • min() rejects dates earlier than the supplied lower boundary and can customize the error.
  • max() rejects dates later than the supplied upper boundary and can customize the error.
  • An error function can distinguish missing input from other invalid date input.

Common mistakes

  • This validates Date objects, not date strings; a string must be converted or handled with a string/date schema first.
  • An ISO timestamp string is rejected directly because the input is not a Date instance.

Example: Validate a Date within a range

import { z } from "zod";

const DateSchema = z.date()
  .min(new Date("1900-01-01"), { error: "Too old" })
  .max(new Date("2100-01-01"), { error: "Too far in the future" });

const result = DateSchema.safeParse(new Date("2025-06-15"));
console.log(result.success); // true

Creates a date schema, constrains it to an inclusive range, and validates a JavaScript Date without throwing on failure.

When to use it

Runtime Date validation

Validate values received from application code after they have been parsed into Date objects.

Date range constraints

Prevent timestamps outside a permitted historical or future range.

Custom validation errors

Return tailored messages for missing and invalid date inputs.

Interview questions

QWhat does z.date() accept?

z.date() validates JavaScript Date instances. A Date object passes, whereas an ISO-formatted string fails direct validation.

Follow-up: How would you enforce a date range? Use .min() for the earliest allowed Date and .max() for the latest allowed Date.

QHow do you constrain the permitted dates?

Call min() with a Date to reject earlier values and max() with a Date to reject later values. Both methods can receive an error customization object.

Follow-up: How can a caller inspect failure without catching an exception? Use safeParse(), which returns a result containing success and either data or validation errors.

QHow can z.date() errors be customized?

The schema can be configured with an error callback, which receives the issue and can choose messages based on the input. The documentation demonstrates a required-input message and an invalid-date message.

Follow-up: What should be used when the input is text rather than a Date? Choose a suitable string schema or transform/convert the input before applying z.date().

  • z.coerce.date()
  • z.iso.datetime()
  • z.codec()
  • min()
  • max()
  • safeParse()

Source: Defining schemas | Zod. Checked 2026-10-15.