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

1 Answer 1

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) %}
1
  • Thank you very much Paul, your code worked and taught me something new. Commented Oct 3, 2014 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.