Yii Framework Forum: Cjuidatepicker Not Saving To Database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cjuidatepicker Not Saving To Database 0000-00-00 Rate Topic: -----

#1 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 11 February 2013 - 09:09 PM

Not sure what's going on, but I can't save the date submitted by form data, it always saves 0000-00-00.
_form.php
	<div class="row">
		<?php echo $form->labelEx($model,'svc_date'); ?>
        <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model' => $model,
            'attribute' => 'svc_date',
            'options' => array(
                'appendText' => ' - mm/dd/yyyy',
                'dateFormat' => 'mm/dd/yy'
            )
        )); ?>
		<?php echo $form->error($model,'svc_date'); ?>
	</div>


I thought that maybe this was due to input not being an actual date, so I added a conversion event:
    protected function beforeSave()
    {
        if($this->svc_date)
        {
            $this->svc_date = date('m/d/Y', strtotime($this->svc_date));
        }
        return parent::beforeSave();
    }

but this made no difference.

MySQL field is set to DATE
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 11 February 2013 - 09:25 PM

Dear Friend

You change the dateFormat in widget in the following way.

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


Then there is no need to override the beforSave method.

Regards.
0

#3 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 11 February 2013 - 09:44 PM

View Postseenivasan, on 11 February 2013 - 09:25 PM, said:

Dear Friend

You change the dateFormat in widget in the following way.

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


Then there is no need to override the beforSave method.

Regards.

Ah, this works well, thank you! Much appreciated.

How do I go about setting my desired date and time format? Is this constraint due to MySQL table field?
0

#4 User is offline   guaruja 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 10-March 12

Posted 12 February 2013 - 07:20 AM

View Posthaosmark, on 11 February 2013 - 09:44 PM, said:

Ah, this works well, thank you! Much appreciated.

How do I go about setting my desired date and time format? Is this constraint due to MySQL table field?



MySQL is only accepting english notation, therfore you have to add a conversion layer between user input and db.
For this you could use a behavior like i18n-datetime-behavior
(if you decide to use this extensions also take a look at the valueable comments that other users made, especially this and this. Could you save some debugging issues... ;) )
0

#5 User is offline   haosmark 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 27-January 13

Posted 12 February 2013 - 09:23 AM

Nice, I'll be looking into that.
Thank you.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users