Skip to content

Date Rules ​

Date rules validate parseable dates, exact date formats, and date ordering against literal dates or other request fields. Attribute rules use ComparisonTarget for string targets; fluent rules use typed date values or property expressions.

Date ​

Requires the value to be a date or date/time value that can be parsed.

csharp
[Date]
csharp
RuleFor(x => x.StartsAt)
    .Date();

DateFormat ​

Requires the value to be a date string matching the exact configured format.

csharp
[DateFormat(string format)]

[DateFormat("yyyy-MM-dd")]
csharp
RuleFor(x => x.BirthDate)
    .DateFormat("yyyy-MM-dd");

After ​

Requires the value to be after a literal date or another request field.

csharp
[After(string target, ComparisonTarget targetType = ComparisonTarget.Value)]

[After("2026-01-01")]
[After("StartsAt", ComparisonTarget.Field)]
csharp
RuleFor(x => x.EndsAt)
    .After(x => x.StartsAt);

AfterOrEqual ​

Requires the value to be after or equal to a literal date or another request field.

csharp
[AfterOrEqual(string target, ComparisonTarget targetType = ComparisonTarget.Value)]

[AfterOrEqual("2026-01-01")]
[AfterOrEqual("StartsAt", ComparisonTarget.Field)]
csharp
RuleFor(x => x.EndsAt)
    .AfterOrEqual(x => x.StartsAt);

Before ​

Requires the value to be before a literal date or another request field.

csharp
[Before(string target, ComparisonTarget targetType = ComparisonTarget.Value)]

[Before("2026-12-31")]
[Before("EndsAt", ComparisonTarget.Field)]
csharp
RuleFor(x => x.StartsAt)
    .Before(x => x.EndsAt);

BeforeOrEqual ​

Requires the value to be before or equal to a literal date or another request field.

csharp
[BeforeOrEqual(string target, ComparisonTarget targetType = ComparisonTarget.Value)]

[BeforeOrEqual("2026-12-31")]
[BeforeOrEqual("EndsAt", ComparisonTarget.Field)]
csharp
RuleFor(x => x.StartsAt)
    .BeforeOrEqual(x => x.EndsAt);

DateEquals ​

Requires the value to equal a literal date or another request field.

csharp
[DateEquals(string target, ComparisonTarget targetType = ComparisonTarget.Value)]

[DateEquals("2026-07-20")]
[DateEquals("ExpectedDate", ComparisonTarget.Field)]
csharp
RuleFor(x => x.DueDate)
    .DateEquals(x => x.ExpectedDate);

All packages are released under the MIT License.