Rahul Patel Rahul Patel -4 years ago 253
PHP Question

Yii2 : Get selected dropdown value

The DB have record with birthdate. I want to select year from year dropdown for inserted DB date.
The DB will have birthdate in the format m/d/Y e.g.(08/15/1990).
I want to select year 1990 for above date in the edit form.

<?= $form->field($model, 'year')->dropDownList($year, array('prompt' => 'YYYY')); ?>

Answer Source

Please try following code.

I assumed that birth_date is the database field which have the date.

$model->year = date('Y',  strtotime($model->birth_date));

Let me know if you still find any problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download