title: PHP Regular Expression to Change Date Format
body: <p>I almost tried for 10 hours to change the date format suits my needs but couldn't success. I have tried Preg_Replace Strotime functions with following examples.</p>
  
  <p>The current date format is : 02-25-2006
  Want to convert to: 2006-02-25</p>
  
  <p>Here are the list of examples I have tried:</p>
  
  <pre><code>publishdate = "02-20-2012";  
  echo preg_replace("/\d{2}-\d{2}-\d{4}/","$3/$1/$2",$publishdate); 
  
  $dateString= '2006-09-14';
  echo date("m/d/Y", strtotime($dateString));
  
  
  
  $dateString1= '02-20-2012';
  echo date("Y/m/d", strtotime($dateString1));
  
  
  
  $date1 = '05-25-2010';
  echo date('Y-m-d', strtotime($date1));
  
  $dateString2= '02-20-2012';
  echo preg_replace("/(\d{2})-(\d{4})-(\d{2})/","$2/$3/$1",$dateString2);  
  </code></pre>