I'm performing an entity query that searches for nodes of my custom content type called 'news'. The content type has a date field called 'field_date'. I want to be able to perform the query in a way that only produces the 'news' nodes that have a 'field_date' that fits within a specified year. Here is an attempt I made below.
$year = 2015; $query = \Drupal::entityQuery('node') ->sort('field_date', 'DESC') ->condition('type', 'news') ->condition('field_date', [date('Y','field_date'), $year], '=') ->range(0, 10);
In the code above I'm attempting to only grab the year from the 'field_date' datefield and compare that to $year, 2015 in this case. However I receive SQL errors like:
Invalid parameter number: number of bound variables does not match number of tokens
I'm guessing part of it is date('Y','field_date') doesn't know what 'field_date' is but I'm not sure how to go about it.
How do I make a year comparison on a datefield in a entityquery condition?