title: Check if dates match in javascript
body: <p>I'm creating a custom ASP.Net validator that checks if the data entered is a non working day.</p>
  
  <p>The definition of "non working day" is:</p>
  
  <ol>
  <li>The date is either a Saturday or Sunday</li>
  <li>The date is a national holiday</li>
  </ol>
  
  <p>I've coded the c# stuff and have created expando attributes for the error message and a string of holiday dates. Having done that, I've created a javascript function that contains this code to check for none working days. I've removed other code for brevity.</p>
  
  <pre><code>if (sender.NonWorkingDayErrorMessage &amp;&amp; sender.Holidays) {
  
      // Is weekend
      if (date.getDay() == 6 || date.getDay() == 0) {
          sender.innerHTML = sender.NonWorkingDayErrorMessage;
          return;
      }
  
      // Is holiday
      var holidays = sender.Holidays.split(";");
  
      for (var i = 0; i &lt; holidays.length; i++) {
  
          var h = new Date(Date.parse(holidays[i]));
  
          if (h === date) {
              sender.innerHTML = sender.NonWorkingDayErrorMessage;
              return;
          }
      }
  }
  </code></pre>
  
  <p>The issue I have is that the code h === date is always false - here's the output I get when I add an alert and type in 26/8/2013.</p>
  
  <blockquote>
    <p>Mon Aug 26 2013 00:00:00 GMT+0100 (GMT Standard Time) => Mon Aug 26 2013 00:00:00 GMT+0100 (GMT Standard Time) => false</p>
  </blockquote>
  
  <p>As you can see I parse the holidays but I also test the input 'date' like this further up the function like this:</p>
  
  <pre><code>// Deconstruct string and reconstruct
  // as date.
  var parts = args.Value.split("/");
  var day = parseInt(parts[0],10);
  var month = parseInt(parts[1],10) -1;
  var year = parseInt(parts[2],10);
  var date = new Date(year, month, day);
  
  // Valid date format but not a valid date
  if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
      sender.innerHTML = sender.InvalidErrorMessage;
      return;
  }
  </code></pre>
  
  <p>Anyone got ideas as to why these two dates aren't seen as matches? </p>