title: Need help to extract year from date?
body: <p>I am using regular expression to match date format. and also extract year, month, date from date. but I am unable to get complete year value here . if I am enter <code>2013-02-29</code> than I am getting <code>20</code> in year instead of <code>2013</code>. What I am trying here is :- </p>
  
  <pre><code>$(document).ready(function(){
      var dateVal = '2013-06-01';
      var rxDatePattern = /^(19|20)\d\d(-)(0[1-9]|1[012])(-)(0[1-9]|[12][0-9]|3[01])$/;
      var dtArray = dateVal.match(rxDatePattern);
  
      dtYear = dtArray[1];
      dtMonth = dtArray[3];
      dtDay = dtArray[5];
  
      jQuery.each(dtArray, function(index, value) {
          console.log(index + ': ' + value);
      });
  }); 
  </code></pre>
  
  <p>I am getting output :- </p>
  
  <pre><code>0: 2013-06-01
  
  1: 20
  
  2: -
  
  3: 06
  
  4: -
  
  5: 01
  </code></pre>
  
  <p>here is fiddle : <a href="http://jsfiddle.net/roop1886/rYh8N/1/" rel="nofollow">http://jsfiddle.net/roop1886/rYh8N/1/</a></p>
  
  <p>Here is complete code where I am using above code :- </p>
  
  <pre><code>//varify date formate
  jQuery.validator.addMethod(
      "siteDateValidator",
      function (value, element) {
          var currVal = value;
          if (currVal != '') {
              var rxDatePattern = /^(19|20)\d\d(-)(0[1-9]|1[012])(-)(0[1-9]|[12][0-9]|3[01])$/;
              var dtArray = currVal.match(rxDatePattern);
              if (dtArray == null) {
                  return false;
              }
              dtYear = (dtArray[1]);
              dtMonth = (dtArray[3]);
              dtDay = (dtArray[5]);
  
              if (dtMonth &lt; 1 || dtMonth &gt; 12) return false;
              else if (dtDay &lt; 1 || dtDay &gt; 31) return false;
              else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) &amp;&amp; dtDay == 31) return false;
              else if (dtMonth == 2) {
                  var isleap = (dtYear % 4 == 0 &amp;&amp; (dtYear % 100 != 0 || dtYear % 400 == 0));
                      if (dtDay &gt; 29 || (dtDay == 29 &amp;&amp; !isleap)){
                          return false;
                      }
              }
          }
          return true;
      },
      "Please enter a valid date, date format should be(yyyy-mm-dd) and year should be greater than equal to 1900."
  );
  </code></pre>