title: Yii2 - Save and display DateTime in different formats
body: <p>I need save attribute "created_at" in MySQL formatt "yyyy-mm-dd hh:mm:ss", but display in php format "d-m-Y".</p>
  
  <p>It´s works fine in create scenario but when i update any attribute and save, its overwrite "created_at" and set like "0000-00-00 00:00:00" automatically in DB.
  I use two functions in the model <strong>beforeValidade()</strong> and <strong>afterFind()</strong>.</p>
  
  <p><strong>common\models\Oficios.php</strong></p>
  
  <pre><code>public function beforeValidate()
  {
      if ($this-&gt;scenario == self::SCENARIO_CREATE){
          $this-&gt;created_at = date('Y-m-d H:i:s');
      }else {
          $this-&gt;created_at = $this-&gt;created_at;
      }
  
      return parent::beforeValidate(); 
  }
  
  public function afterFind ()
  {
      // convert to display format
      $this-&gt;created_at = strtotime ($this-&gt;created_at);
      $this-&gt;created_at = date ('d-m-Y', $this-&gt;created_at);
  
      parent::afterFind ();
  }
  </code></pre>