Create a View with Exposed Date filters

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:06
    In this chapter we are going to create a view with an exposed date filter.
  • 0:10
    This demonstration will show you how to filter on the content in a date field
  • 0:15
    and also explore other options to us when we expose filters to our users.
  • 0:19
    If you're not familiar with views, we have a whole series on it, so you should check it out.
  • 0:24
    As you can see on my screen, I have the completed version of what we will be building.
  • 0:29
    At the top is our exposed filter provided by the view
  • 0:33
    where we get to say we want our start date and our date content type
  • 0:39
    to be between two different fields.
  • 0:43
    And when I click in there, I actually get a nice little date pop-up.
  • 0:47
    If I go ahead and I can change these fields,
Loading ...

Create a View with Exposed Date Filters

Loading...

In this chapter Michelle will walk us through using our new date field with Views to create a listing of our content showing the dates associated with them. We'll be listing our date content, with an exposed filter for selecting the date range, and we look at how to set relative dates to fill in the form's default values.

You'll need to the Views and Chaos Tools modules for this chapter. If you would like a refresher on using Views, you can watch our Intro to Views for Drupal 7 series.

Note: With an update in Date module (7.x-2.x), you can now change the format of the date in the exposed filter. It's not a completely smooth process, but here are some instructions for how to get this working.

1. Ensure that the following modules and their dependencies are enabled: Date, Date Views, Date Popup, Views UI.
2. Add a date field to a content type. Collect only the date (not the time -- uncheck hours, minutes, seconds). Create some content with a date.
3. Create a new view of fields filtered by the content type in which you added a date field.
4. Update the format as described in the video to table and add a label to the Title field.
5. Add the date field to fields. Choose the "short" format to display.
6. Add the date field to filters. Select "day" as granularity.
7. Expose the date filter. Configure it as described in the video.
8. The exposed date filter should show a long format in the text field, which is not what we want.
9. In a new tab, go to Configuration > Regional and Language > Date and time > Types
10. For the Date Type of "Short", select the 2nd option (10/21/2014 - 12:29). Save configuration.
11. Go back to your view and refresh the page. The date popup format should now be in the short format. It should now respect whatever format you choose for "Short" in the Date and Type settings.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.