1

Drupal 7.23, Views 7.x-3.7
I have a Calendar Event content type, with a date field.
In my view, I need to pass a date range as a contextual filter such that if the event's date falls within the specified range, the events is returned.
In other words, something like /events-calendar/2013-09-04/2013-09-30 should return any events happening for the rest of this month. So far I'm only able to match a single date, not a range.
Any ideas appreciated.

  • Could you provide your desired filtering as a pseudocode algorithm? I've seen quite too many ideas how such filtering should really work to dare to guess. – Mołot Sep 4 '13 at 9:21
4

Assuming that you have set up your contextual filters properly, all you need to do is change the format of the date you pass.

/events-calendar/20130904--20130930

That above format should do the trick.

  • In case anyone's interested, I set up these links in a block, and the code looks like this: echo "<br/><a href=\"/events-calendar/"; echo date('Ymd', strToTime('first day of this month')); echo "--"; echo date('Ymd', strToTime('last day of this month')); echo "\">This Month</a>"; – Sam Moore Sep 4 '13 at 15:19
  • Glad it helped :) – Gokul N K Sep 5 '13 at 6:24
1

If you are looking for ranges in general within the contextual filters then you should consider using the Views Contextual Range Filter module. Some more details about it:

Views Contextual Range Filter is a simple plugin for Views that adds the option to contextually filter not just by a single value, but also by range.

Numeric, alphabetical and list ranges are all supported. Node ids, user ids and even taxonomy term ids are all special cases of numbers so will work also. Range-filtering on dates is also supported. For this you may use either the absolute date format as dictated by Views, YYYYMMDD, or the relative format, which supports natural language phrases like six months ago, today noon and even first Tuesday of November.

Please be aware that contextual filters are different from exposed filters. This module is about contextual filters only.

You may use the OR operator (i.e. +) and the negate operator. You negate by ticking the "Exclude" box on the Views Contextual filter configuration panel, in the "More" section.

  • Adding this a separate answer this is not exactly what you asked for. But might help others who are looking for this. – Gokul N K Sep 4 '13 at 9:58
  • I will definitely check this out, as it looks as if it might prove useful elsewhere. Thanks for your input and your answer (sorry I don't have enough reputation points to vote up your answers - kinda new here :-) – Sam Moore Sep 4 '13 at 15:07
  • Except that project specifically says that for dates, using the Date module, you don't need the contextual_range_filter module... – artfulrobot Sep 26 '13 at 21:33

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.