I want a time/date format in a View that renders like this when a time ends in :00
Sep. 16, 2017 - 2pm

BUT, renders like this only if minutes are present:
Sep. 16, 2017 - 2:30pm

Currently, I use this format: M. d, Y - g:ia but I need a way to make those zeros disappear when an event starts at the top of the hour.

2 Answers 2


you can use views conditional module, from module page:

Views Conditional is a simple module that allows you to define conditionals (if xxx then yyy) with fields in views. Conditions include: Equal To Not Equal To Greater Than Less Than Empty Not Empty Views conditional allows you to output text based on the result of the condition.

and here is a tutorial how to use it, https://www.youtube.com/watch?v=LIyZV_Hhccw

  • This seems to be an acceptable solution in this instance. My view is setup like this: -Date Field 1 (M. d, Y - g:ia) [hidden field] -Date Field 2 (M. d, Y - ga) [hidden field] -Views Conditional: If Date Field 1 contains :00, render [Date Field 2] else render [Date Field 1] My view is complicated by some dates having end times as well, but I think I can build something that works.
    – Tantalus
    Commented Sep 6, 2017 at 18:04

A bit of a cludge but if your output allows simple html, you can write a format that includes a span around the colon and minutes and use the minutes as a class. Then hide the span if it's 00. E.g.

M. d, Y - g<\s\p\a\n\ \c\l\a\s\s='\m\i\n-i'>:i<\s\p\a\n\>a

Then css of

.min-00 { display: none; }

I've done this with dates to produce over/under large date/small month displays. If it's coming from a view, you may need to check the allow html option on the field.

  • 1
    Best hack I've seen in ages, bravo
    – Clive
    Commented Sep 6, 2017 at 17:04

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.