0

Following what described in Views filter criteria date field is greater than current date, I have used operator >= today with some success. I would like to create "future" nodes and they should be filtered out as well. What I need is for a date and time field to be filtered for today's date only. I have tried many things to include:

  • operator = today + either value type, machine readable or offset (returns no results)

  • operator = now + either value type, machine readable or offset (returns no results)

  • contextual filter: summary links (granularity not adjustable that I can find so returns multiple summary links for a single date & summary + a summary link is not a good UI for the application)

  • contextual filter: default value - "current date" (doesn't work; known issue with variably effective patch to core which I'd like to avoid) ref: https://www.drupal.org/project/drupal/issues/2325899

  • date only field (doesn't work due to UTC time & changes during daylight savings)

1 Answer 1

1

Figured this out. Have to add the following 2 filters:

operator is "Is greater than or equal to" value is today

AND

operator is "Is less than" value is today +24 hours

Notes:

Must use "Is greater than or equal to" to include today at midnight and must use "Is less than" to filter out tomorrow at midnight.

It does not matter what value type you select, machine readable or offset.

The value "today" literally returns the time of midnight on today's date. This means setting operator Is equal to "today" only returns results dated on exactly midnight of today, hence why zero results were returned.

SQL for "today" taken from Views query:

DATE_FORMAT(('2020-03-29T07:00:00' + INTERVAL -25200 SECOND), '%Y-%m-%d\T%H:%i:%s'))

"+ INTERVAL -25200 SECOND" is -7 hours correction for my time zone so time is T00:00:00 or midnight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.