recommended mysql DATETIME format
if field create_date is of type DATETIME on a db, you can do this $model = new MyModel(); $model->create_date = date(‘Y-m-d H:i:s’);
$model->save();
configure a CGridView column to display formatted dates
(see more formats: some pre-defined PHP datetime formats)
'columns'=>array(
array(
'name'=>'create_date,
'value'=>'date_format(new DateTime($data->create_date),"d/m/Y")',
'filter'=>false,
'sortable'=>false
),
//..more columns
displaying formatted dates in a CDetailView widget
array(
'name'=>'create_date',
'value'=>date_format(new DateTime($model->create_date),DATE_RFC850)
)
setting a default value in a form model for a DATETIME attribute
say you have a ‘creation_date’ attribute for which you want to set a default value of today’s date and time: edit the rules() method in your model:
public function rules()
{
return [
['date_created','default','value'=>date('Y-m-d H:i:s')],
];
}<br /><br />https://queirozf.com/reminders/dealing-with-and-formatting-dates-on-yii
Просмотров: 2609