jquerycodeigniterdatepickerjquery-jtable

Cant get the date from datepicker in filter input


I added a jquery datepicker to my filter input in my jTable but when i set the startDate and endDate it returns 0 results. And even if i type in the dates manually still returns 0 records.

Here is my view.php

 <form class="searchbox_1">

        Date from <input class="search_1" type="text" name="from_date" id="from_date"/>

        Date to <input class="search_1" type="text" name="to_date" id="to_date"/>

        <center><button  class="submit_1" type="submit" id="LoadRecordsButton">Search</button>

            <input class ="submit_1" type="reset" value="Clear fields!"></center>

    </form>
</div>
<div id="countryTable"></div>
<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jTable
        $('#countryTable').jtable({
        title: 'Country\'s',
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'country_name ASC',
                selecting: true,
                multiselect: true,
                selectingCheckboxes: true,
                selectOnRowClick: true,
                actions: {
                        listAction:   'bla',
                        createAction: 'bla1',
                        updateAction: 'bla2',
                        deleteAction: 'lba1'
                },
                fields: {

           record_date: { title: 'Record Date',
                          type: 'date',
                          displayFormat: 'mm/dd/yy',
                          create: false,
                          edit: false,
                          sorting: false
                        }
                },

$('#from_date').datepicker({
            onSelect: function(dateText, inst){
        $('#to_date').datepicker('option', 'minDate', new Date(dateText));
            }
        });

        $('#to_date').datepicker({
            onSelect: function(dateText, inst){
        $('#from_date').datepicker('option', 'maxDate', new Date(dateText));
            }
        });

        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#countryTable').jtable('load', {
),
                from_date: $('#from_date').val(),
                to_date: $('#to_date').val()
            });

        });

        $('#LoadRecordsButton').click();

    });



</script>

I'm using codeigniter if you need any other information please let me know.


Solution

  • you need to convert datetimepicker to datetime format before insert to database.

     $myTime = strtotime("08/19/2016 1:45"); 
         echo date("Y-m-d H:i:s", $myTime);