title: Compare two dates in JS
body: <p>I want to compare the user's birthday against today's date and get the number of days in between. The birthday they enter will be in the form of <em>12/02/1987</em> in an input box of type <em>text</em></p>
  
  <p>In my JS file I have code that looks like this: </p>
  
  <pre><code>function validateDOB(element) {
  var valid = false;
  
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth() + 1; //do that January is NOT represented by 0!
  var yyyy = today.getFullYear();
  
  if (dd &lt; 10) {
      dd = '0' + dd
  }
  if (mm &lt; 10) {
      mm = '0' + mm
  }
  
  var today = mm + '/' + dd + '/' + yyyy;
  alert(today);
  if (element.value != today) {
      var days = 0;
      var difference = 0;
  
      Christmas = new Date("December 25, 2011");
  
      today = new Date();
  
      difference = today - Christmas
  
      days = Math.round(difference / (1000 * 60 * 60 * 24)-1);
      alert(days); 
      valid = true;
  }
  </code></pre>
  
  <p>Instead of using "Christmas" I want to compare <code>element.value</code>... how do I do this?</p>
  
  <p>When I put <code>difference = today - element.value</code> it won't show me the difference. The alert box comes up as <code>NaN</code>. </p>