Drupal Views filter on a Date field does not work as expected

I have a Drupal7 view which includes a field of Date type (let’s say "activity date") via a relationship. I want to filter this field by "today" (show only activities with activity date equal to today). (The module Date Views is installed.)

So I created a Filter on this field and this relationship, choose the Operator "is equal to" and the option "An offset from the current time such as "+1 day" or "-2 hours -30 minutes"" with the value "today". This returns 0 results, although I am sure I have activities with activity date == today.

Then, I tried the other operators, and it seems several of them are broken. Only "greater than or equal to" and "less than or equal to" work as expected. "Less than" + "today" as well as "Greater than" + "today" show also activities with activity date == today. "Is not equal to" + "today" shows all activities, also those with activity date == today. If I use the view without any date filters, these activities and their dates show correctly.

I even tried "Is between" + "today" + "today" which returns 0 results as well. "Is between" + "yesterday" + "tomorrow" returns all the activities from yesterday, today and tomorrow (so this means that the min and max values are inclusive, not exclusive, which is why today+today should work as well).

As "greater than or equal to" +today and "less than or equal to" +today work as expected, I thought I could put those two filters on the view together to achieve the results for "today", but both of them together return 0 results again.

Then, I tried to use a Contextual Filter. I could choose between the normal activity date field and the activity date field in the form of CCYYMMDD. When I choose the latter, and combine it with "Provide default value" > "Current date", this works, but the timezone is wrong and the day ends at 10 pm, so activities with a date after 10pm are not shown. I think the reason for that is the date form CCYYMMDD does not contain the time and thus UTC is used as default. When I use the normal activity date field and combine it with "Provide default value" > "Current date", it shows 0 results again.

How can I do this simple filter for the current date? It seems like a basic functionality to me.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal Views filter on a Date field does not work as expected

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.