CJuiDatePicker

This is my code in model rules…

array(‘dataMedicao’, ‘type’, ‘type’ => ‘date’, ‘message’ => ‘{attribute}: is not a date!’, ‘dateFormat’ => ‘yyyy-MM-dd’),

        array('dataMedicao', 'default',


            'value' => new CDbExpression('NOW()'), //automatically add the current date in mysql feild


            'setOnEmpty' => true, 'on' => 'update'),


        array('date_created,date_modified', 'default',


            'value' => new CDbExpression('NOW()'),


            'setOnEmpty' => false, 'on' => 'insert'),

protected function beforeSave() {

    $this->dataMedicao = new CDbExpression('NOW()');


    return parent::beforeSave();


}





protected function afterFind() {


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


    return TRUE;


}

This is my code in Form…

<?php echo $form->labelEx($model, ‘dataMedicao’); ?>

    &lt;?php


    &#036;this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(


        'name' =&gt; 'dataMedicao',


        'attribute' =&gt; 'dataMedicao',


        'value' =&gt; &#036;model-&gt;dataMedicao,


        // additional javascript options for the date picker plugin


        'options' =&gt; array(


            'showAnim' =&gt; 'fold',


            'dateFormat' =&gt; 'yy-mm-dd',


        ),


        'htmlOptions' =&gt; array(


            'style' =&gt; 'height:20px;'


        ),


    ));


    ?&gt;

<?php echo $form->error($model, ‘dataMedicao’); ?>

In my DB dates are set to 0000-00-00 and when I list them they get set to 1970-01-01… Then on update I use the DatePicker to set the date to update the field, but it always gets update to the current date we are on… How do I get the date I set in the DatePicker and how do I save it in my DB?!

Thanks for all the help…

this right here is your problem


protected function beforeSave()

{

    $this->dataMedicao = new CDbExpression('NOW()');

    return parent::beforeSave();

}

datemedicao is always current date no mater what

To what should I change it then??.. I need to get the date set in the date picker.

Thank’s for all the help.

just remove it as you already have validation rule in place for default value incase the field is empty

It worked… Many thanks! :)