Good morning, If have have a URL that passes parameters: http://url?month=January&Year=2018, how would I go about querying all entries in section where the postDate equals January 2018?
I can get the parameters by using: craft.app.request.getParam('month')
and craft.app.request.getParam('year')
but I can seem to figure out the correct way to only show me entries based on these parameters.
Thanks in advance.
I noticed a post that had the following answer and the response was that it worked. I tried it, and received the error:
Object of class DateTime could not be converted to string
.
{% set month = craft.request.getParam('month') %}
{% set year = craft.request.getParam('year') %}
{% set firstDayOfMonth = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %}
{% set lastDayOfMonth = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %}
{% set entries = craft.entries.section('yourSection').postDate('and', '>= ' ~ firstDayOfMonth, '<= ' ~ lastDayOfMonth) %}