3

I'm taking the month and year from parameters in the url like this...

{% set month = craft.request.getParam('month') %}
{% set year = craft.request.getParam('year')  %}

The url would look like this: ?month=September&Year=2014

... and want to return entries from a specific section where the postDate month and year match those parameters.

Be very grateful for any pointers.

Thanks Lee

user1070143
  • 1,106
  • 12
  • 24

1 Answers1

8

You could try this (not tested):

{% 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) %}
Paul
  • 6,338
  • 12
  • 26