Use created year as condition in Entity Query I'm performing an entity query that searches for nodes of my custom content type called 'news'. I want to perform the query in a way that only produces the 'news' nodes that have a Authored Date that fits within a specific date . Here is an attempt I made below.
' 

$year = 2018-02;
$query = \Drupal::entityQuery('node')
  -&gt;condition('type', 'news')
  -&gt;condition('created', [date('Y-M','created'), $year], '=')
  -&gt;range(0, 10);
Try this function get_nodes_by_authored_month_date('news', '2018-02')



use Drupal\node\NodeInterface;

 /**
 * @param string $bundle_type
 * @param string $year_month
 *
 * @return array|int
 */
function get_nodes_by_authored_month_date($bundle_type = '' , $year_month = '') {

  $full_date = date_parse_from_format('Y-m', $year_month);
  //- Get number of days of month
  $number_of_days_of_month = cal_days_in_month(CAL_GREGORIAN, $full_date['month'], $full_date['year']);
  //- Get the timestamp of the first minute in the month 
  $first_minute_of_month = mktime(0, 0, 0, $full_date['month'], 1, $full_date['year']);
  //- Get the timestamp of the last minute in the month
  $last_minute_of_month = mktime(23, 59, 59, $full_date['month'], $number_of_days_of_month, $full_date['year']);

  $query = \Drupal::entityQuery('node')
    ->condition('status', NodeInterface::PUBLISHED)
    ->condition('type', $bundle_type)
    ->condition('created', [$first_minute_of_month, $last_minute_of_month], 'BETWEEN')
    ->range(0, 10);

  return $query->execute();
}