Datepicker in Yii is storing data as yy MM d format
Try this:
protected function afterFind(){
parent::afterFind();
$this->due_date=date('d F, Y', strtotime(str_replace("-", "", $this->due_date)));
}
protected function beforeSave(){
if(parent::beforeSave()){
$this->due_date=date('Y-m-d', strtotime(str_replace(",", "", $this->due_date)));
return TRUE;
}
else return false;
}
Add the above code to your model. And it should work.
I had a similar problem with european dates, formatted like: 'dd/mm/yyyy', and this is what i use:
In model rules:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('date','date','format'=>Yii::app()->locale->getDateFormat('medium')),
because 'medium' locale format fits my validation needs.
In the form I use:
<?php echo $form->labelEx($model,'date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
//'name'=>'date',
'model'=>$model,
'attribute'=>'date',
'language'=>Yii::app()->language=='es' ? 'es' : null,
'options'=>array(
'changeMonth'=>'true',
'changeYear'=>'true',
'yearRange' => '-99:+2',
'showAnim'=>'fold', // 'show' (the default), 'slideDown', 'fadeIn', 'fold'
'showOn'=>'button', // 'focus', 'button', 'both'
'dateFormat'=>'dd/mm/yy',
'value'=>date('dd/mm/yy'),
'theme'=>'redmond',
'buttonText'=>Yii::t('ui','Select form calendar'),
'buttonImage'=>Yii::app()->request->baseUrl.'/images/calendar.gif',
'buttonImageOnly'=>true,
),
'htmlOptions'=>array(
'style'=>'vertical-align:top',
'class'=>'span2',
),
));?>
<?php echo $form->error($model,'date'); ?>
And the conversion back to MySQL format, for save, date comparisons...:
$date=strftime('%Y-%m-%d', strtotime(str_replace("/", "-", $this->date)));
Hope this helps.