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

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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