title: Convert and insert two date formats MYSQL
body: <p>I'm facing an issue with managinging dates, some dates pass others dont. I want to produce an insertable date for mysql. there are two possible types of post dates</p>
  
  <pre><code>yyyy-mm-dd //should go without conversion
  m/d/yyyy  // should be converted
  </code></pre>
  
  <p>I'm using this</p>
  
  <pre><code> $date = $_REQUEST['date'];
   $date_regex = '/(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/';
   if(preg_match($date_regex, $date)){
   $date = DateTime::createFromFormat('m/d/Y',$date)-&gt;format('Y-m-d');}
  </code></pre>
  
  <p><strong>problems</strong></p>
  
  <p>I realised this regex is failing for dates like </p>
  
  <pre><code>2/5/2013 
  </code></pre>
  
  <p>but has been working for</p>
  
  <pre><code> 12/12/2013
  </code></pre>
  
  <p>so I removed it BUT still </p>
  
  <pre><code>DateTime::createFromFormat('m/d/Y',$date)-&gt;format('Y-m-d');
  </code></pre>
  
  <p>is also failing for m/d/yyyy</p>
  
  <p>This date thing has got my head spinning for the last 6 hours.</p>