Issue With Cjuidatepicker

Hi Guys,

I am getting into Yii and using it for a small project. I am using CJuiDatePicker for a date field. In the database the field is defined as a DATE (MYSQL btw). I have the following code in my view:


<div class="row">

		<?php echo $form->labelEx($model,'ProbDate'); ?>

		<?php /* echo $form->textField($model,'ProbDate',array('size'=>60,'maxlength'=>255)); */?>

		<?php                    

			$this->widget('zii.widgets.jui.CJuiDatePicker',array(

                                'attribute' => 'ProbDate',

                                'value' => $model->ProbDate,

                                'model' => $model,

                                'options'=>array(

                                'showAnim'=>'slideDown',

                                'showButtonPanel'=> 'true',

                               //'dateFormat'=>'yyyy-mm-dd',  // optional Date formatting

                                ),

                                

                                'htmlOptions'=>array(

                                'style'=>'height:10px;'

                                

                                ),

                        ));                 

        ?> 

        

        <?php echo $form->error($model,'ProbDate'); ?>

	</div>




	<div class="row">

		<?php echo $form->labelEx($model,'ProbFName'); ?>

		<?php echo $form->textField($model,'ProbFName',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($model,'ProbFName'); ?>

	</div>



And I have the following code segment in my model:




protected function beforeSave(){

     $this->ProbDate = date('YYYY-MM-DD', strtotime( $this->ProbDate));

    return parent::beforeSave();

}

	

No matter what I do to change this, I always get 0000-00-00 as a result. I have tried changing this value to something else physically in the database, but 0000-00-00 always gets written in when I submit an entry. I am using Yii Framework version 1.1.14 Any help would be appreciated. I can’t find any good resources for this and was hoping some of you experts have seen this before.

If you use the dateFormat in the Cjuidatepicker it must be only 2 ‘yy’ like:


'dateFormat'=>'yy-mm-dd'

And in the beforesave, use ‘Y-m-d’ not ‘YYYY-MM-DD’ like this:


$this->ProbDate = date('Y-m-d', strtotime( $this->ProbDate));

To learn more, check out http://php.net/manual/en/function.date.php for the right format chars.

Totally fixed it. I have been struggling over this for a while. Thanks for the link as well. Much appreciated.