我正在尝试在表单中使用日期选择器,但在提交之后,该值被存储为数据库中的000-00-00,并且在提交表单后查看详细信息时,将显示minDate值。
同一日期选择器正在以其他形式正常工作,我正在尝试重复使用日期选择器。
file.js
function userDetailsEventHandlers() {
$('.date-picker').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd-MM-yy',
yearRange: '1900:1998',
minDate: '01-January-1900',
maxDate: '31-December-1998',
});
}
form.php
<div class="form-group">
<?php echo $form->labelEx($model,'DOB'); ?>
<?php echo $form->textField($model,'DOB', array('class' => 'form-control date-picker')); ?>
<?php echo $form->error($model,'DOB'); ?>
</div>
模型类:
protected function afterFind() {
if (!empty($this->DOB)) {
$this->DOB = date('d-F-Y', strtotime($this->DOB));
}
return parent::afterFind();
}
数据库中的数据类型: datetime (我也尝试使用date)。使用datepicker的其他形式的数据类型是datetime。
发布于 2017-05-12 10:50:06
最后使用CJuiDatePicker,:P
<div class="form-group">
<?php echo $form->labelEx($model,'DOB'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'model' => $model,
'attribute' => 'DOB',
'language'=> 'en',
'name'=>'datepicker-month-year-menu',
//'flat'=>true,//remove to hide
'options'=>array(
'dateFormat' => 'yy-mm-dd',
'showAnim'=>'slide',//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
'changeMonth'=>true,
'changeYear'=>true,
'yearRange'=>'1900:1998',
// 'minDate' => '2000-01-01', // minimum date
// 'maxDate' => '2099-12-31', // maximum date
),
'htmlOptions'=>array(
'class' => 'form-control',
'style'=>''
),
));
?>
</div>
发布于 2017-05-04 06:49:56
$('.date-picker').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd-MM-yyyy', <------------ Make this changes
yearRange: '1900:1998',
minDate: '01-01-1900', <------------ Make this changes
maxDate: '31-12-1998',
});
}
正如您将日期格式指定为‘dd’一样,需要以相同的格式传输minDate和maxDate。还要确保在服务器side.if上传递的是哪种格式,而不是yyyy-MM-dd
,您需要使用STR_TO_DATE()
手动将字符串内容转换为日期。试试上面的代码。希望这能帮上忙。
发布于 2017-05-04 06:50:26
我认为问题在于日期格式,因为您的日期选择器使用日期格式:
'01-January-1900'
// which is different then 'Y-m-d'
但是日期列的默认格式是'Y-m-d'
,如果数据格式不正确,它将插入000-00-00
。因此,将您的约会更改为'Y-m-d'
,然后再试一次。
https://stackoverflow.com/questions/43775726
复制相似问题