Looking for some suggestions on how to best accomplish this. We want to set up a filter on a date field to display just content with a date within the current (or next or previous) academic year, defined as May 1-April 30.

Using the great Views between dates filter (https://www.drupal.org/project/views_between_dates_filter) we can do the filter, but the exact relative format string elludes us, and quite likely can't be achieved without writing some code.

What we have so far is a start set to "first day of may" and end set to "last day of april +1 year", but of course as soon as we hit January 1st that blows up.

Can anyone recommend a different approach or even better module that makes this happen?

  • Can you provide a bit more context? Are you trying to make this an exposed filter so that users can choose the academic year and get results for that year? Or will this be pre-set to display a specific year? Also: does your content have separate start and end dates, or just a single date?
    – Aaron
    Sep 17, 2015 at 21:00
  • Just a single date, and not an exposed filter. We are going to just have three defined view displays, one for each.
    – Jason Reid
    Sep 18, 2015 at 16:08
  • Ah, then there no need to use views_between_dates_filter. I'll add an answer momentarily.
    – Aaron
    Sep 18, 2015 at 16:09

1 Answer 1


There's no need for views_between_dates_filter for this use-case. You might consider turning on the date_views module because it provides some niceties, but if you're using core date properties (like Post Date or Updated Date) then you don't even need that. Just add 2 filters to your view:

  • One set to only show content where the date field is greater than or equal to your specific desired start date (2015-05-01 00:00:00 for instance)
  • One set to only show content where the date field is less than or equal to your specific desired end date (2016-04-30 23:59:59 for instance).

You don't need relative dates at all since you're setting up distinct views for each year.

  • The thing is we don't want to have to update the view every year, which hard coding the dates would require.
    – Jason Reid
    Sep 18, 2015 at 16:22
  • @JasonReid In a comment above, you mentioned you'll have "three defined view displays, one for each"...one for each what? Are you saying you want three separate views, one which always shows last academic year, one which always shows the current academic year, and one which always shows the upcoming year? And you want to avoid having to touch them every year?
    – Aaron
    Sep 18, 2015 at 16:24
  • Yes. One display for the previous year (relative to the current date), the current year, and the next year.
    – Jason Reid
    Sep 18, 2015 at 18:31
  • @JasonReid got it. Then I think you'll need either use hook_views_pre_execute() to hack in your changes to the date values, or (the better way) write a custom filter handler.
    – Aaron
    Sep 18, 2015 at 18:34

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.