Event archives with custom date field
Try this:

{% set entriesInYear = craft.entries
    .section('agenda')
    .limit(null)
    . dateAndTime([
        'and',
        '&gt;=' ~ year,
        '&lt;' ~ (year + 1)
    ])
    .all()
%}


The .before() and .after() methods are convenience methods that hide the complexity of the date query on Craft's postDate field. They don't affect any other custom date fields like your dateAndTime field.

The array for your dateAndTime field condition (in the above example) is more of a Yii Framework query thing where the optional 'and' operator in the first position means all of the following conditions must apply. If omitted, it's assumed to be 'or'.

If you prefer, the array can also be expressed as a string of comma-separated conditions like so:

.dateAndTime('and, &gt;= ' ~ year ~ ', &lt; ' ~ (year + 1))