title: How do validate one datetime is newer than another datetime clientside and post warning if failed
body: <p>I have 2 input fields that has a datepicker each, none of them are required, but if they are entered then field 1 must be lower (Newer) than the other.</p>
  
  <p>So I found <a href="http://webcloud.se/log/Form-validation-with-jQuery-from-scratch/" rel="nofollow">http://webcloud.se/log/Form-validation-with-jQuery-from-scratch/</a> but I cant figure out how to make this work, I created this Jquery</p>
  
  <pre><code>        $('#resource_form').validate({
              rules: 
                  {
  
              DateIn: 
                  {
              check: function () {
                  if($('#resource_datein').val() == '' || $('#resource_dateout').val() == '') {
                      return true;
                  }
                  else if($('#resource_datein').val() &lt; $('#resource_dateout').val()) {
                      return true;
                  }
                  else {
                      return false;
                  }
              }
      },
          messages: 
              {
                  DateIn:{
                      check: "Date out must be earlier than returned date"
              }
  
          }
      }
  
  });
  </code></pre>
  
  <p>This is then supposed to validate this html </p>
  
  <pre><code>                &lt;div id="ExpectedReturn"&gt;
                      &lt;div class="editor-label"&gt;
                          @Html.LabelFor(m =&gt; m.Resource.ExpectedReturn)
                      &lt;/div&gt;
                      &lt;span class="editor-field"&gt;
                          @Html.TextBoxFor(m =&gt; m.ExpectedReturn.Date, new { @Id = "resource_datereturn", @class = "datepicker", maxlength = "10" })
                          @Html.TextBoxFor(m =&gt; m.ExpectedReturn.Hour, new { @Id = "resource_hour", maxlength = "2" })
                          :
                          @Html.TextBoxFor(m =&gt; m.ExpectedReturn.Minute, new { @Id = "resource_minute", maxlength = "2" })
                      &lt;/span&gt;
                      &lt;span&gt;
                          @Html.ValidationMessageFor(m =&gt; m.ExpectedReturn.Date)
                          @Html.ValidationMessageFor(m =&gt; m.ExpectedReturn.Hour)
                          @Html.ValidationMessageFor(m =&gt; m.ExpectedReturn.Minute)
                      &lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div id="DateIn"&gt;
                      &lt;div class="editor-label"&gt;
                          @Html.LabelFor(m =&gt; m.Resource.DateIn)
                      &lt;/div&gt;
                      &lt;span class="editor-field"&gt;
                          @Html.TextBoxFor(m =&gt; m.DateIn.Date, new { @Id = "resource_datein", @class = "datepicker", maxlength = "10" })
                          @Html.TextBoxFor(m =&gt; m.DateIn.Hour, new { @Id = "resource_hour", maxlength = "2" })
                          :
                          @Html.TextBoxFor(m =&gt; m.DateIn.Minute, new { @Id = "resource_minute", maxlength = "2" })
                      &lt;/span&gt;
                      &lt;span&gt;
                          @Html.ValidationMessageFor(m =&gt; m.DateIn.Date)
                          @Html.ValidationMessageFor(m =&gt; m.DateIn.Hour)
                          @Html.ValidationMessageFor(m =&gt; m.DateIn.Minute)
                      &lt;/span&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>Which is part of</p>
  
  <pre><code>@using (Ajax.BeginForm("CreateResource", "Resource", new { }, new AjaxOptions { HttpMethod = "Post", OnSuccess = "systematic_resource.successRequest" }, new { Id = "resource_form" }))
  </code></pre>
  
  <p>The thing I am not sure about is how I make the DateIn in my JQuery refere to my @Id = "resource_datereturn" I cant see how I am supposed to link them together so it makes the check on that inputfield. The <a href="http://docs.jquery.com/Plugins/Validation/validate" rel="nofollow">http://docs.jquery.com/Plugins/Validation/validate</a> doc seems pretty useless.</p>