How to Add the Current Date to a View in Drupal 7
Today, someone in IRC asked how to add the current date to a View they were working on. Seemed simple enough, and I offered to help, thinking it was just a matter of sticking a token in the View header. And it was...sort of. Incredibly, Google searches turned up only code-based solutions. Overkill. Here's a UI-based approach.
To add the current date to the top of a View, follow these steps:
- Install and enable the Token Filter module.
- Go to Configuration > Content authoring > Text formats.
- Choose a text format to edit, and under Enabled filters check the box for Replace tokens.
- In another tab, pull up the List of tokens for Drupal 7.
- Go to your View.
- Add a Header, using the Global: Text area option. (You can find the Header in the center column of the full Views UI.)
- Paste the token for your preferred date format into the big text field, and make sure to choose the Text format you enabled token replacement for.
That should do it! Apply your header to the appropriate display(s), and you should see the date in your preview.
Happy Drupaling!