<p>I found the solution by using the following:</p>

<pre><code>{% set startDate = now %}
{% set endDate = (now | date_modify("+2 months")) %}
{% set allTraining = craft.lowblocks.blocks.fieldId(72).type("trainingDateTimeDateTime").order("dateTimeFrom").limit(null) %}
{% set entryIds = [] %}
{% for course in allTraining %}
    {% if (course.dateTimeFrom &gt;= startDate) and (course.dateTimeFrom &lt;= endDate) %}
        {% set entry = course.owner %}
        {% set entryIds = entryIds | merge([entry.id]) %}
    {% endif %}
{% endfor %}
{% set entries = craft.entries.section("training").id(entryIds).fixedOrder(true).status("live,pending") %}
</code></pre>

CC BY-SA 3.0
2015-03-09T22:40:09.747Z
Is there any way in Craft 2.3 that this is doable without the use of a plugin? I have a matrix field with a date in it and I want to pull out the last 3 entries. 

Almost exactly what you have, but native.
Aaron
CC BY-SA 3.0
2014-11-28T15:33:49.623Z
2014-11-28T15:33:49.623Z
Sean Delaney
<p>I want to list all entries in a section by custom date time fields.</p>

<p>A training course has a From field and a To field. These fields are inside a <em>Matrix</em> field.</p>

<p>The field name storing this info is called <code>trainingDateTime</code>.</p>

<p>The Matrix block is called <code>trainingDateTimeDateTime</code>.</p>

<p>The Matrix fields in this block are called and <code>dateTimeFrom</code> and <code>dateTimeTo</code> both <em>datetime</em> fields.</p>

<p>My entries loop so far is:</p>

<pre><code>{% set entries = craft.entries.section("training") %}
</code></pre>

<p>I know you can do order entries by a custom <em>datetime</em> field using something like:</p>

<pre><code>{% set entries = craft.entries.section("training").customDateTime.('&gt;= ' ~ now).order('customDateTime DESC') %}
</code></pre>

<p>But since I'm using a <em>matrix</em> field I'm unsure how to approach this.</p>

<p>I'm wanting to show all upcoming training courses from the current month up till the next 2 months.</p>

<entries><matrix><datetime><ordering>
Get entries by custom matrix / date time field
# Get entries by custom matrix / date time field

(Asked by: username_0 on 2014-11-28)

I want to list all entries in a section by custom date time fields.
A training course has a From field and a To field. These fields are inside a Matrix field.
The field name storing this info is called trainingDateTime.
The Matrix block is called trainingDateTimeDateTime.
The Matrix fields in this block are called and dateTimeFrom and dateTimeTo both datetime fields.
My entries loop so far is:
{% set entries = craft.entries.section("training") %}

I know you can do order entries by a custom datetime field using something like:
{% set entries = craft.entries.section("training").customDateTime.('>= ' ~ now).order('customDateTime DESC') %}

But since I'm using a matrix field I'm unsure how to approach this.
I'm wanting to show all upcoming training courses from the current month up till the next 2 months.

**Tags:** entries, matrix, datetime, ordering


---

## 1 answers

### Answer by username_0 on 2014-11-28. Score: 2 | Accepted answer

I found the solution by using the following:
{% set startDate = now %}
{% set endDate = (now | date_modify("+2 months")) %}
{% set allTraining = craft.lowblocks.blocks.fieldId(72).type("trainingDateTimeDateTime").order("dateTimeFrom").limit(null) %}
{% set entryIds = [] %}
{% for course in allTraining %}
    {% if (course.dateTimeFrom >= startDate) and (course.dateTimeFrom <= endDate) %}
        {% set entry = course.owner %}
        {% set entryIds = entryIds | merge([entry.id]) %}
    {% endif %}
{% endfor %}
{% set entries = craft.entries.section("training").id(entryIds).fixedOrder(true).status("live,pending") %}

> **Comments:**
> **username_1**: Is there any way in Craft 2.3 that this is doable without the use of a plugin? I have a matrix field with a date in it and I want to pull out the last 3 entries.   Almost exactly what you have, but native.  

---

