date cannot initialise to default (‘0000-00-00’)
I have a kartik datepicker which presents the following error on save
Database Exception – yii\db\Exception
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: ‘<span class=“not-set”>(not set)</span>’ for column ‘date_of_birth’ at row 1
The SQL being executed was: INSERT INTO registration
(firstname
, email
, telephone
, box_no
, postal_code
, town
, home_address
, home_number
, type
, date_of_birth
) VALUES (‘w.w. Sires’, ‘’, ‘0722339988’, ‘’, ‘’, ‘Nairobi’, ‘’, ‘’, ‘2’, ‘<span class=\“not-set\”>(not set)</span>’)
Error Info: Array
(
[0] => 22007
[1] => 1292
[2] => Incorrect date value: '(not set)' for column 'date_of_birth' at row 1
)
I have tried the following in vain
_form.php
<?php
// Usage with model (with no default initial value)
echo ‘<label class=“control-label”>Birth Date</label>’;
echo DatePicker::widget([
'model' => $model,
'attribute' => 'date_of_birth',
'value' => '0000-00-00',
'options' => ['placeholder' => 'Enter Date Of Birth ...'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-M-yyyy'
]
]);
?>
Registration model
public function rules()
{
return [
[['date_of_birth'], 'default', 'value' => '0000-00-00'], //if not set enter '0000-00-00'
['date_of_birth', 'compare', 'compareValue' => 18, 'operator' => '>='], //if set ensure itss > 18yrs
];
}