kikimor/yii-mysql-datetime-behavior

There is no license information available for the latest version (1.1.2) of this package.

MySQL datetime behavior for Yii-1

1.1.2 2015-02-25 16:25 UTC

This package is auto-updated.

Last update: 2024-12-08 05:56:23 UTC


README

What is it?

Automatically converts date and datetime fields between ActiveRecord model and MySQL database for Yii framework.

How to instal?

composer require kikimor/yii-mysql-datetime-behavior dev-master

How to configure?

<?php
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
  		],
  	]);
  }
}

How to use?

$model = Model::model()->findByPk(1);
echo $model->date; // 25.02.2015
$model->date = '26.02.2015';
$model->save();