title: How can I get year month and day from a string of numbers?
body: <p>I have a date that is given to me in the form <code>20111213 (YYYYMMDD)</code> and I am trying to separate the parts into day, month and year. I am using this code:</p>
  
  <pre><code>$day = substr($string, 6, 8);
  $month = substr($string, 4, 6);
  $year = substr($string, 0, 4);
  $final = $day . "-" . $month . "-" . $year;
  echo $final;
  </code></pre>
  
  <p>but that gives me the output</p>
  
  <pre><code>13-1213-2011
  </code></pre>
  
  <p>As you can see, the month gets interpreted as 4 characters and I can't get it just to output 12. Cheers for the help.</p>