I have a views view that displays a list of events. These events have a start-date and an end-date. I have two exposed filters, one for the start-date and one for the end-date, so that users can select a date range to view events. The page can be seen here:

KODE Calendar page

The filters check that start-date <= selected start-date and that end-date is >= selected end-date. This works if the event spans several days and start- and end-date falls outside the selected dates.

The question is, how can I include events that have start-date and end-date on the same day?

I tried to have another set of filters and use the and/or functionality, but alas, I was not able to reuse the exposed filter.

My filter criteria

  • I answered similar question here: drupal.stackexchange.com/questions/73119/… If this answer is insufficient, please clarify why your situation is different, and I'll see what I can do.
    – Mołot
    May 16, 2013 at 12:42
  • The difference now is that the filters are exposed, and that I am not able to reuse the exposed filters so that I can solve it like the similar question. A solution could be to reuse said filters, but I can not find any way to do this.
    – pusle
    May 16, 2013 at 12:46
  • In condition like published AND language AND ( content_without_end_date OR (content_with_end_date AND end_date_ok ) ) why would you ever need to use end date twice? It appears only once. Checking for it's very existence does not need to be exposed, right?
    – Mołot
    May 16, 2013 at 12:52
  • Because then I could also include events where start-date >= selected start-date, and end-date is <= selected end-date. I will try to find out how I can rewrite my question, it probably wasn't to obvious.
    – pusle
    May 16, 2013 at 13:20
  • The question is, how can I include events that have start-date and end-date on the same day? Well, I can't see why this should malfunction with filters like start-date <= selected start-date and end-date is >= selected end-date You have no results if start-date == end-date?
    – Mołot
    May 16, 2013 at 13:27

1 Answer 1


Since I was completely unable to make myself understood when asking the question, I thought maybe the solution could clear things up. In the views view I filter event dates like specified in the question. I then used the hook_views_query_alter to add an or group condition like so:

function MYMODULE_views_query_alter (&$view, &$query) {
  if ($view->name != 'events') { return; }

  global $language;
  $lang = $language->language;

  $start_date = isset ($_GET['field_from_date_value']['value']['date']) ? $_GET['field_from_date_value']['value']['date'] : date('Y-m-d');
  $end_date   = isset ($_GET['field_from_date_value2']['value']['date']) ? $_GET['field_from_date_value2']['value']['date'] : date('Y-m-d');

  $query->group_operator = 'OR';

  $status_condition = array (
    'field' => 'node.status',
    'value' => 1,
    'operator' => '='

  $node_type_condition = array (
    'field' => 'node.type',
    'value' => array ('event'),
    'operator' => 'in'

  $language_condition = array (
    'field' => 'node.language',
    'value' => array ($lang),
    'operator' => 'in'

  $date_condition_value = array (
    'field' => "DATE_FORMAT(field_data_field_from_date.field_from_date_value, '%Y-%m-%d') >= :field_data_field_from_date_field_from_date_value",
    'value' => array (':field_data_field_from_date_field_from_date_value' => $start_date),
    'operator' => 'formula'

  $date_condition_value2 = array (
    'field' => "DATE_FORMAT(field_data_field_from_date.field_from_date_value2, '%Y-%m-%d') <= :field_data_field_from_date_field_from_date_value2",
    'value' => array (':field_data_field_from_date_field_from_date_value2' => $end_date),
    'operator' => 'formula'

  $condition_type = 'AND';

  $query->where[10]['conditions'] = array (

  $query->where[10]['type'] = $condition_type;


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.