Drupal 7, Views node to be selected on date range.

I would like to have my view only return nodes that were created last month, no matter when I run the view this month. So as it's the middle of January, I want all nodes created in December last year, and next month I want all of January's

So the dates would be between first day of last month and the last day of last month.

In php I can use:

echo date('Y m d', strtotime('first day of last month')) 


echo date('Y m d', strtotime('last day of last month')) 

to get the correct date range.

However, in Drupal, the SQL does not create the correct ranges.

Viewing the view and sql logs at 11:55 on Jan 16th 2013 I see :

(node.created >= 1358337264-2678400

which works out as 2012-12-16 11:54:24, so it is a month ago, but not the first day of that month.

Any thoughts.


3 Answers 3


If possible, it might be beneficial to create a separate Date field for your content type. I often find that if I need to do custom filtering in a view, filtering by the date field instead of node post date is much easier. Being able to collect different granularity such as day and month can be helpful also.


The following seems to work. It must be a bug in views

first day of -2 month for the min

last day of -2 month for the max

  • The sql generated by first day -2 month is (node.created BETWEEN 1358342287-5270400 AND 1358342287-2764800) which becomes 61 and 32 days, but should be 61 + 16 and 32 + 16 ( as it is the 16th of January) Commented Jan 16, 2013 at 13:27
  • I am getting the correct result in the views. get the content posted from dec 1st to dec 31st Commented Jan 16, 2013 at 13:38

Try to set your granularity to month and set the filter only to

equals = last month

This works for me.

Edit: Geoff Charlton is using node post date for filtering and not a date field. No granularity can be set on post date.

  • I misunderstood the question, sorry for irritation.
    – Volker
    Commented Jan 16, 2013 at 14:03

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.