title: CodeIgniter Datatable Date Search Range
body: <p>I need to find data from a certain date range. Please help me</p>
  
  <p>Model</p>
  
  <pre><code>public function Date($start_date, $end_date){
  
  $query = $this-&gt;db-&gt;select($this-&gt;tables['table_search'])
      -&gt;where($this-&gt;tables['table_search'].'.created_at &gt;=', $start_date)
      -&gt;where($this-&gt;tables['table_search'].'.created_at &lt;=', $end_date)
      -&gt;group_by($this-&gt;tables['table_search'].".created_at")
      -&gt;get($this-&gt;tables['table_search']);
  
  return $query-&gt;result_array();
  }
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>public function Date()
      {
          $start_date = $_POST['start_date'];
          $end_date = $_POST['end_date'];
  
          $return = $this-&gt;m_model-&gt;Date($start_date,$end_date);
  
          echo json_encode($return);
      }
  </code></pre>
  
  <p>Ajax J'S</p>
  
  <pre><code>$('.input-daterange').datepicker({
  todayBtn: 'linked',           
  format: "yyyy-mm-dd",
  autoclose: true
  });
  </code></pre>
  
  <p>function fetch_data(start_date='', end_date=''){
              var dataTable = $('#table').DataTable({
              "processing": true,
              "serverSide": true,
              "order":[],
              "ajax":{
              url: "search/Date",
              type: "POST",
              data:{
              start_date:start_date, end_date:end_date
              },
              success:function(data){
              $('#table').html(data);
              }
              }
              });
              }</p>
  
  <pre><code>        $('#search').click(function(){
  
          var start_date = $('#start_date').val();
          var end_date = $('#end_date').val();
  
          if(start_date != '' &amp;&amp; end_date != ''){
          $('#table').DataTable().destroy();
          fetch_data(start_date,end_date);
          }else{
          }
  </code></pre>