title: javascript Datetime compare
body: <p>I need to compare two date in javascript.</p>
  
  <p>In my code I am calling a web service method which serialize and returns in JSON format an instance of the following class</p>
  
  <pre><code>public class MyPeriod
  {
      public int PeriodID { get; set; }
      public DateTime BeginDate { get; set; }
      public DateTime FirstDeadline { get; set; }
      public DateTime SecondDeadline { get; set; }
      public DateTime EndDate { get; set; }
  } 
  </code></pre>
  
  <p>this will produces a JSON fragment like this:</p>
  
  <pre><code>{
      "d": {
          "PeriodID":26,
          "BeginDate":"\/Date(1321743660000)\/",
          "FirstDeadline":"\/Date(1322002860000)\/",
          "SecondDeadline":"\/Date(1322002860000)\/",
          "EndDate":"\/Date(1322168400000)\/"
      }
  }
  </code></pre>
  
  <p>Now I need to compare <code>FirstDeadline</code> with <code>SecondDeadline</code> and so in my javascript I have a fragment like this</p>
  
  <pre><code>var date1 = eval(data.d.FirstDeadline.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
  var date2 = eval(data.d.SecondDeadline.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
  if (date1 === date2) {
      ...
  }
  </code></pre>
  
  <p>Unfortunately the equal comparison does not work even if the dates have the same value. 
  Any help?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I forgot to mention that I need to compare only the date part (that's way I am not comparing the milliseconds since the epoch). </p>