title: Javascript parseInt gives very unexpected results
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/850341/workarounds-for-javascript-parseint-octal-bug">Workarounds for JavaScript parseInt octal bug</a>  </p>
  </blockquote>
  
  
  
  <p>I'm parsing a string to check if it's a date, and by chance we now discovered that my method doesn't work for dates in august or september. This is what I do (the input isn't <em>really</em> hard-coded, obviously, but for brevity...):</p>
  
  <pre><code>var str = '2010-08-26 14:53';
  var data = str.split(' ');  // ['2010-08-26', '14:53']
  var date = data[0].split('-'); // ['2010', '08', '26]
  var time = data[1].split(':'); // ['14', '53']
  
  var yyyy = parseInt(date[0]); // 2010
  
  // THIS IS WHERE STRANGE THINGS HAPPEN:
  var MM = parseInt(date[1]); // 0 - not 08 or 8, as expected!
  console.log(date[1]); // prints "08" (with quotes)
  console.log(date[1].toString()); // prints 08 (no quotes)
  console.log(parseInt(date[1].toString())); // prints 0 (!)
  </code></pre>
  
  <p>This problem arises for august and september, and for the 8th and 9th every month - that is, when either <code>"08"</code> or <code>"09"</code> is being parsed to integer, <code>0</code> is returned instead of <code>8</code> or <code>9</code>. The code works for both lower (e.g. <code>"07"</code>) and higher (e.g. <code>"10"</code>) integers (at least within expected date ranges...)</p>
  
  <p>What am I doing wrong?</p>