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.
- Open a new browser tab (trust me, it’s just easier this way), and go to http://www.yoursitename.com/admin/config/regional/date-time.
- Choose the tab that reads Formats.
Alternatively, you could go directly to http://www.yoursitename.com/admin/config/regional/date-time/formats/add). This will allow you to input a “date format string,” which is basically just a date formatted in PHP language.
- Add the format you want as per the PHP.net’s date format guide.
Note: the string does accept colons. I wanted, for instance, something like 11:26PM, so I wrote g:iA.
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.