Get entries by custom matrix / date time field 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.('&gt;= ' ~ 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.
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 &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") %}