title: "Call to a member function format() on a non-object" when converting date in PHP
body: <p>I can not get rid of this error message:</p>
  
  <blockquote>
    <p>Call to a member function format() on a non-object</p>
  </blockquote>
  
  <p>So, I go on googling and get some good source like <a href="https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php">this StackOverflow question</a>.</p>
  
  <p>I tried to do something similar, but I failed. This is my code :</p>
  
  <pre><code>$temp = new DateTime();
  /*ERROR HERE*/ $data_umat['tanggal_lahir'] = $data_umat['tanggal_lahir']-&gt;format('Y-m-d');
  $data_umat['tanggal_lahir'] = $temp;
  </code></pre>
  
  <p>So, i did trial &amp; errors, and I found out if I do this:</p>
  
  <pre><code>$data_umat['tanggal_lahir'] = date("Y-m-d H:i:s");
  </code></pre>
  
  <p>The date will successfully converted, BUT it always return today's date (which i dont want).</p>
  
  <p>I want to convert the date so that <code>10/22/2013</code> will be <code>2013-10-22</code>.</p>