Show nodes relative to a date with Views
Say you want to create a listing with nodes where the publishing date is not older than two months. How do you go about this? In this example I will use the Article content type which comes with Drupal after a fresh install. For this tutorial you will need to have installed and activated the Date module.
- First off create a view which shows nodes of the Article content type (you can turn on additional options like creating a menu link if you like). Click on 'Continue & edit'.
- You can adjust your 'Title', 'Format' and 'Fields' options as you please but the fun part starts with the 'Filter'. Click on 'Add' next to 'Filter Criteria'.
- Select 'Date' in the 'Filter' dropdown. And check 'Date: Date (node)' and click on 'Apply all displays' (If you don't see 'Date' in your 'Filter' dropdown please make sure you have installed the Date module).
- In the settings make sure you select 'Text' below 'Date selection form element' and check 'Content: Post date' below 'Date field(s)'. You can change the other settings as you wish or leave them be. Click on 'Apply and continue'.
- Now comes the tricky part. This can be a trial and error exercise but if you want to show articles which have been posted the last two months your settings will have to be as follows. First select 'Is greater than' below 'Operator'. Next select 'Enter a relative date' by clicking on the 'Select a date' dropdown. Now you will have the option to enter a relative date. In this example I will use '-2 months' as a relative date. For more examples you can check this page on php.net. Click on 'Apply all displays'.
- Below you will see a preview and you can check if the view will display the right results. If this not to your liking you can click on 'Settings' next to 'Date: Date (node) (Content: Post date > -2 months)' below your 'Filter criteria'. Here you can tweak the relative date settings. As I said before you might have to try a few different settings before you get the right results.
- Save your view and you're done!
How did this work for you? Need any help? Let me know in the comments and I will try to give you some pointers.
Original Article: