Skip to content

.dateTime()

Passes for the extended format, such as 2026-06-17, 2026-06-17 12:00 or 2026-06-17T12:00:00.000Z. Impossible dates and times such as 2023-02-30 or 25:00 fail, and so does the basic format without separators, 20260617. Every accepted string is also accepted by DateTime.parse.

StringValidator<O> dateTime({String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code invalidDateTime. Default message: value must be a valid date. value is replaced by the field name when there is one.

@IsDateTime(), or the constant @isDateTime. A DateTime parameter, nullable or not, gets .dateTime() without any annotation, because JSON carries dates as strings. DateTime elements of lists and maps get it too. Put the annotation on the constructor parameter or the field.

final date = l.string().dateTime();
date.validate(input)+2-3
  1. valid: '2026-10-04'
  2. valid: '2026-10-04T10:15:00Z'
  3. invalid: '2023-02-30'value must be a valid date
  4. invalid: '20261004'value must be a valid date
  5. invalid: 'yesterday'value must be a valid date