How to use database BETWEEN query? I need to fetch the database records for particular date using database query , i tried some queries to fetch but it showing all records in table .

controller.php

public static function load($entry = array()){
$maxDate = \Drupal::request()-&gt;query-&gt;get('set_start_date');
$minDate = \Drupal::request()-&gt;query-&gt;get('set_end_date');
 $select = db_select('pastpayments', 'x');
 $select-&gt;fields('x');
 foreach ($entry as $field =&gt; $value) {
 $select-&gt;condition('paiddate', $maxDate, "&lt;=");
 $select-&gt;condition('paiddate', $minDate, "&gt;=");
}
 return $select-&gt;execute()-&gt;fetchAll();
}  

public function entryList() {
$content = array();

$content['message'] = array(
  '#markup' =&gt; $this-&gt;t('Generate a list of all entries in the database. There is no filter in the query.'),
);

$rows = array();
$headers = array(t('Member Id'), t('Name'), t('Paid Date'), t('Paid Date'));

foreach ($entries = $this-&gt;load() as $entry) {
  // Sanitize each entry.
  $rows[] = array_map('Drupal\Component\Utility\SafeMarkup::checkPlain', (array) $entry);
}
$content['table'] = array(
  '#type' =&gt; 'table',
  '#header' =&gt; $headers,
  '#rows' =&gt; $rows,
  '#empty' =&gt; t('No entries available.'),
);
// Don't cache this page.
$content['#cache']['max-age'] = 0;

return $content;


}



  how  i can fetch the table records for particular date ranges


database query

mysql&gt; select * from pastpayments where paiddate &gt;='2017/03/01' and paiddate &lt;='2017/03/30';
You can use BETWEEN like this:

$query-&gt;condition('myfield', array(5, 10), 'BETWEEN');


In your case:

$query-&gt;condition('paiddate', array('2017/03/01', '2017/03/30'), 'BETWEEN');


For more information see the Conditional Clauses documentation.

It depends on how your dates are stored as to what min and max values you should pass in.

For example it could be a unix timestamp or it could be an actual date.
I would recommend doing a more generic select on the data to find out the format of the dates and then replicate that format in the values that you are passing in.