Query entries by custom date field (for a particular year) So I'm trying to get all entries that have a particular year assigned to a custom date field. (Could be any day/month in that year).

The custom field is startDate and my attempt at a query - which doesn't work - is below...

PS. year is a 4 digit variable set via the last segment of the url and pulled into the template as a variable, and giving you 2018, 2019 or whatever...

{% set query = {
  section: 'programme',
  isOngoing: 0
} %}
{% set programmeEntries = craft.entries(query).search('startDate:' ~ year|date('Y-m-d')) %}


PS. I think it's more like this but I can't get the syntax right...

{% set query = {
  section: 'programme',
  isOngoing: 0,
  startDate: ( ['and', '&gt;=' ~ (year~'-01-01')|date('Y')|atom, '&lt;=' ~ (year~'-01-01')|date('Y')|date_modify('+12 months')|atom])
} %}
I think your problem is you're converting the date to a year string then converting that to an atom value. Just convert the date straight to an atom value:

{% set yearStart = "#{year}-01-01"|atom %}
{% set yearEnd = "#{year}-12-31"|atom %}

{% set entries = craft.entries({
    section: "programme",
    isOngoing: 0,
    startDate: ["and", "&gt;= #{yearStart}", "&lt; #{yearEnd}"]
}).all %}