title: Compare Dates DataAnnotations Validation asp.net mvc
body: <p>Lets say I have a StartDate and an EndDate and I wnt to check if the EndDate is not more then 3 months apart from the Start Date</p>
  
  <pre><code>public class DateCompare : ValidationAttribute 
   {
      public String StartDate { get; set; }
      public String EndDate { get; set; }
  
      //Constructor to take in the property names that are supposed to be checked
      public DateCompare(String startDate, String endDate)
      {
          StartDate = startDate;
          EndDate = endDate;
      }
  
      public override bool IsValid(object value)
      {
          var str = value.ToString();
          if (string.IsNullOrEmpty(str))
              return true;
  
          DateTime theEndDate = DateTime.ParseExact(EndDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
          DateTime theStartDate = DateTime.ParseExact(StartDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture).AddMonths(3);
          return (DateTime.Compare(theStartDate, theEndDate) &gt; 0);
      }
  }
  </code></pre>
  
  <p>and I would like to implement this into my validation</p>
  
  <blockquote>
    <p>[DateCompare("StartDate", "EndDate", ErrorMessage = "The Deal can only be 3 months long!")]</p>
  </blockquote>
  
  <p>I know I get an error here... but how can I do this sort of business rule validation in asp.net mvc</p>