.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.
Signature
Section titled “Signature”StringValidator<O> dateTime({String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”@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.
Example
Section titled “Example”final date = l.string().dateTime();required DateTime createdAt, // l.string().dateTime().required()DateTime? deletedAt, // l.string().dateTime()date.validate(input)+2-3- valid:
'2026-10-04' - valid:
'2026-10-04T10:15:00Z' - invalid:
'2023-02-30' - invalid:
'20261004' - invalid:
'yesterday'