haosmark
(Haosmark)
February 12, 2013, 2:09am
1
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
seenivasan
(Chellamnivas)
February 12, 2013, 2:25am
2
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.
haosmark
(Haosmark)
February 12, 2013, 2:44am
3
seenivasan:
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?
guaruja
(Wilnis)
February 12, 2013, 12:20pm
4
haosmark:
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… )
haosmark
(Haosmark)
February 12, 2013, 2:23pm
5
Nice, I’ll be looking into that.
Thank you.