Tag Archives: Views

No, I will not date you! Add only the time to a calendar view in Drupal.

Standard

Note: This is for a Drupal 7 install.

This is a wholly random post, and will (probably) not be followed up by anything useful. Basically, I’m posting this both so I don’t forget how I did it, and so it might help someone else.

Context:  I was making an event calendar in views, to be used as a block elsewhere on my site.  I chose two fields to show on the event calendar – Title and Date.  The Title field was all good.  The Date field, however contains two parts – the event’s date, and the event’s time.  The time I obviously needed.  The date, however, was already implied, since, ya know, this is a calendar.

Question:  How do I force my date field to show just the time?

Answer:  Create a new date format!

It’s a pretty easy, totally point n’ click, and no coding needed!

1)  Make a new date format.

2)  Make a new date type.

  • Navigate back to the Date  and time page (www.yoursitename.com/admin/config/regional/date-time) and click Add date type.
  • Give it a name – preferably a self-explanatory name.
  • Then, under the Date Format dropdown menu, choose the date format you just created above.
  • Click the Add date type button beneath.  This will take you back (yet again!) to the Date and time page.
  • Click Save configuration.

3)  Give that views thing another shot.

  • Head back over to your view, refresh (save first if you need to!).
  • Try modifying the date field again.  This time, the dropdown menu, Formatter, will have your new format.

4)  Click save.

5) Rejoice.  And maybe get some sleep.

Advertisements