Search code examples
phpdatepickerjscript

Getting the selected year from a customed year picker


I have this custom datepicker which I named as yrpicker.

$('.yrpicker').datepicker({
  format: "yyyy",
  autoclose: true,
  minViewMode: "years"
});

enter image description here

This displays only the year-format.

But my problem is whenever I select a year ex. 2010, and save it on the database, I only get the current year which is 2017. How can I fetch the selected desire year.

Below is my php declaration and my html form.

<div class="form-group col-md-2">
<label for="elem_school">Started</label>
    <input type="text" class="form-control datepicker yrpicker" name="elem_yrStarted" id="yrStarted" placeholder="From">
</div>

enter image description here

enter image description here


Solution

  • just replace

    $elemgraduate=date('Y',strtottime($_POST['elem_yrGrad']));
    $elem_yrStarted=date('Y',strtottime($_POST['elem_yrStarted']));
    $elem_lastYearAttended=date('Y',strtottime($_POST['elem_lastAttended']));
    

    WIth

    $elemgraduate=$_POST['elem_yrGrad'];
    $elem_yrStarted=$_POST['elem_yrStarted'];
    $elem_lastYearAttended=$_POST['elem_lastAttended'];
    

    Regards :)