Skip to content
Michal Altair Valášek edited this page May 28, 2024 · 2 revisions

DateOffset

Validates if given DateTime falls within defined offset from current date. Useful for validating birthdates etc.

Attribute

[DateOffset(-120, 0)]             // date must be between 120 years ago and DateTime.Today
[DateOffset(null, "30.00.00.00")] // date must be between DateTime.Now and DateTime.Now + 30 days

Notes

By default, the attribute ignores time of day when comparing. If you want to take it in account, set CompareTime to true and modify error message formatting to show the time of day as well.

Clone this wiki locally