How to display entries with a custom date field within month
Solution 1:

The problem with your code is, that you apply the date filter exclusively to the year variable:


  {% set firstDayOfMonth = month ~ "/1/" ~ year|date("U") %}


To get this right you have to first compose your "datetime string" and then apply the filter to the string as a whole:

{% set firstDayOfMonth = (month ~ "/1/" ~ year)|date("U") %}


That's also the reason why it works for you to apply it inside the query.

.

Solution 2:

You don't need to pass a unix datetime formated string to your query, a string in format "Y-m-d" is just fine:

{% set firstDayOfMonth = year ~ "-" ~ month ~ "-01" %}
{% set daysInThisMonth = firstDayOfMonth|date('t') %}

{% set lastDayOfMonth = year ~ "-" ~ month ~ "-" ~ daysInThisMonth %}

{% set thisMonthsEvents = craft.entries.section('events').eventDate('and', '&gt;= ' ~ firstDayOfMonth, '&lt;= ' ~ lastDayOfMonth) %}