<p>You won't be able to paginate messageList, because that's just an array... According to the <a href="http://buildwithcraft.com/docs/templating/paginate#parameters" rel="nofollow noreferrer">official documentation on the <code>{% paginate %}</code> tag</a>, only an <strong>ElementCriteriaModel</strong> can be paginated.</p>

<p>To see how to create an ElementCriteriaModel which has already been filtered by month, check out <a href="https://craftcms.stackexchange.com/a/447/45">Solution #2 in this thread...</a></p>

<p>You'll end up with code that looks something like this:</p>

<pre><code>{% set firstDayOfMonth = year ~ "-" ~ month ~ "-01" %}
{% set daysInThisMonth = firstDayOfMonth|date('t') %}
{% set lastDayOfMonth  = year ~ "-" ~ month ~ "-" ~ daysInThisMonth %}

{% set thisMonthsEntries = craft.entries.section('messages').messageDate('and', '&gt;= ' ~ firstDayOfMonth, '&lt;= ' ~ lastDayOfMonth) %}

{% paginate thisMonthsEntries as entriesOnPage %}
    {% for entry in entriesOnPage %}
        {# ... whatever your code does... #}
    {% endfor %}
{% endpaginate %}
</code></pre>

CC BY-SA 3.0
2014-08-09T03:18:17.910Z
You're very welcome! :)
Lindsey D
CC BY-SA 3.0
2014-08-11T16:19:05.760Z
Is it possible to only compare to the month itself so that it finds all entries in that month regardless of year?
a-am
CC BY-SA 3.0
2014-08-11T16:31:19.980Z
The code to pull that off would be very different from what we've got here... This example creates a date **range** (from the 1st - 31st of a given month). What you just described would actually look for multiple ranges across X years. Since the pagination portion of this question has already been answered, I'd suggest posing that as a fresh question.
Lindsey D
CC BY-SA 3.0
2014-08-09T03:16:10.040Z
2014-08-09T03:16:10.040Z
2017-04-13T12:51:00.200Z
Lindsey D
<p>Here is how I am filtering entries by a specific month: </p>

<pre><code>{% set filterId = "July" %}
{% set allEntries = craft.entries.section('messages') %}
{% set filteredEntries = [] %}

{% for msg in allEntries %}

  {% if msg.messageDate | date('F') == filterId | date('F') %}
    {% set filteredEntries = filteredEntries | merge([msg]) %}
  {% endif %}

{% endfor %}

{% set messageList = filteredEntries %}
</code></pre>

<p>How can I paginate messageList? Do I need to filter by month a different way for pagination to work?</p>

<entries><templating><filter>
How do I filter entries by month using custom Date/Time field and paginate them?
# How do I filter entries by month using custom Date/Time field and paginate them?

(Asked by: username_0 on 2014-08-08)

Here is how I am filtering entries by a specific month: 
{% set filterId = "July" %}
{% set allEntries = craft.entries.section('messages') %}
{% set filteredEntries = [] %}

{% for msg in allEntries %}

  {% if msg.messageDate | date('F') == filterId | date('F') %}
    {% set filteredEntries = filteredEntries | merge([msg]) %}
  {% endif %}

{% endfor %}

{% set messageList = filteredEntries %}

How can I paginate messageList? Do I need to filter by month a different way for pagination to work?

**Tags:** entries, templating, filter

---

## 1 answers

### Answer by username_1 on 2014-08-09. Score: 3 | Accepted answer

You won't be able to paginate messageList, because that's just an array... According to the official documentation on the {% paginate %} tag, only an ElementCriteriaModel can be paginated.
To see how to create an ElementCriteriaModel which has already been filtered by month, check out Solution #2 in this thread...
You'll end up with code that looks something like this:
{% set firstDayOfMonth = year ~ "-" ~ month ~ "-01" %}
{% set daysInThisMonth = firstDayOfMonth|date('t') %}
{% set lastDayOfMonth  = year ~ "-" ~ month ~ "-" ~ daysInThisMonth %}

{% set thisMonthsEntries = craft.entries.section('messages').messageDate('and', '>= ' ~ firstDayOfMonth, '<= ' ~ lastDayOfMonth) %}

{% paginate thisMonthsEntries as entriesOnPage %}
    {% for entry in entriesOnPage %}
        {# ... whatever your code does... #}
    {% endfor %}
{% endpaginate %}

> **Comments:**
> **username_1**: You're very welcome! :)  
> **username_0**: Is it possible to only compare to the month itself so that it finds all entries in that month regardless of year?  
> **username_1**: The code to pull that off would be very different from what we've got here... This example creates a date **range** (from the 1st - 31st of a given month). What you just described would actually look for multiple ranges across X years. Since the pagination portion of this question has already been answered, I'd suggest posing that as a fresh question.  

---

