Data Annotation Ranges of Dates

Davy picture Davy · Sep 10, 2009 · Viewed 52k times · Source

Is it possible to use [Range] annotation for dates?

something like

[Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())]

Answer

MarkKGreenway picture MarkKGreenway · May 25, 2010

I did this to fix your problem

 public class DateAttribute : RangeAttribute
   {
      public DateAttribute()
        : base(typeof(DateTime), DateTime.Now.AddYears(-20).ToShortDateString(),     DateTime.Now.AddYears(2).ToShortDateString()) { } 
   }