Search code examples
phpdatabasecodeignitertimepicker

Time picker format changes ,When inserting into database


View:

<div class="col-sm-6">
  <input type="text" class="form-control timepicker" name="shiftStartTime" id="shiftStartTime" required parsley-maxlength="6" placeholder="Shift Start Time" />
</div>

Script

<script type="text/javascript">
$(document).ready(function(){

   $('.timepicker').wickedpicker();

    });   

</script>

Controller code :

$shiftstarttime = $this->input->post('shiftStartTime');

But it is inserting into database as "00:00:12".How to change it to the H:m:s format (ie 12:05:10)


Solution

  • First you need to confirm that in post you are getting correct value if yes then following would work for you

    $input = $this->input->post('shiftStartTime');
    $input = str_replace(" : ", ":", $input);
    $shiftstarttime = date('H:i:s', strtotime($input));