Is there any way to achieve relative date in Views FILTER CRITERIA?

I need a date between 'first day of' and 'last day of'.

Views Contextual Range Filter Module does not work on Drupal 8.4.x.

1 Answer 1


The standard date Views filters in Drupal 8 have two options:

  • A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.
  • An offset from the current time such as "+1 day" or "-2 hours -30 minutes"

The first is an absolute date. The second is a relative date string (I don't know why this is called an offset date).

So, add a filter, choose 'offset' as an option, and then enter your relative date. These work for simple comparisons, and between/not between.

At runtime, the value you entered will be parsed by strtotime(); any date-like string that it will accept can be used. This means that it will be dynamic and always be relative to when the view is executed and not when the view was created. php|architect’s Guide to Date and Time Programming has a nice appendix in it about what are parsable values (and some of the quirks).

Keep in mind that you may need to adjust the cache rules for the view to prevent stale data from being displayed. Also, there is a bug1 regarding time zone handling that has not been committed to core yet, which may result in some weirdness.

1 Barring unforeseen problems, this will be fixed in Drupal 8.5.0.


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.