PHP code example of kikimor / yii-mysql-datetime-behavior
1. Go to this page and download the library: Download kikimor/yii-mysql-datetime-behavior library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kikimor / yii-mysql-datetime-behavior example snippets
use Kikimor\MySQLDateTimeBehavior\MySQLDateTimeBehavior;
...
class model extends \CActiveRecord
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'DateTimeBehavior' => [
'class' => MySQLDateTimeBehavior::class,
'dateFormat' => 'd.m.Y', // by default
'dateTimeFormat' => 'd.m.Y H:i', // by default
],
]);
}
}
$model = Model::model()->findByPk(1);
echo $model->date; // 25.02.2015
$model->date = '26.02.2015';
$model->save();