title: Find HTML Date then Compare to Current Dat
body: <p>I need to alert patrons when the library card is about to, or has expired.  The page they see always displays their expiration date in this format:</p>
  
  <p>EXP DATE:10-08-2011</p>
  
  <p>or</p>
  
  <p>EXP DATE:mm-dd-yyyy</p>
  
  <p>First I need to grab that date and compare it to today's date.  I then need to alert the patron in some way that their card will expire in less than 30 days, or let them know that their card has already expired.</p>
  
  <p>How do I grab that date from the string?
  How do I compare that to today's date?
  How do I make the comparison differentiating between less than 30 days in the future and in the past?
  How create an alert for each scenario?</p>
  
  <p>I'm not looking for a complete solution, just to be pointed in the right direction.</p>
  
  <p>Any help is greatly appreciated, </p>
  
  <p>kern</p>
  
  <p>This is what I ended up doing for the date split and comparison.  As a complete novice, it was easier to conceptualize.  However, please feel free to give advice and cleaner ways to perform this...  Now I just need to figure out how to "grab" the date from the html.</p>
  
  <p>Thanks for the help!</p>
  
  <p>kern</p>
  
  <pre><code>//below split date on hyphens
  
  var s = '10-3-2011';
  var fields = s.split(/-/);
  var month = fields[0];
  var day = fields[1];
  var year = fields[2];
  
  //below replace hyphens with slashes
  var slashDate = (month + "/" + day + "/" + year)
  
  // below convert string to date
  var patexpDate = new Date(slashDate);
  
  //below get todays date
  var todaysDate = new Date();
  
  //below patron expiration date minus todays date
  var diffDates = (patexpDate - todaysDate)
  
  
  if (diffDates &gt;= 0 &amp;&amp; diffDates &lt;= 2592000000) {
  alert('Your Library card expires in less than 30 days.');
  
  }
  
  else if (diffDates &lt; 0) {
  alert("Your Library card has expired.");
  
  }
  
  else alert('Card NOT expired.');
  </code></pre>