This project is read-only.

Change Date Format

Topics: Customizing Orchard, Installing Orchard, Writing themes
Feb 14, 2013 at 10:16 PM

If you look here:, I have created a little Icon for the Date. What I would like to do is remove the time somehow and move the year to below the month and day. Any ideas on how to achieve this easily?

Tommy Havens
Feb 14, 2013 at 11:56 PM
Feb 15, 2013 at 12:45 AM
Im not sure how CSS will change the format. Am I missing something?
Feb 15, 2013 at 1:36 AM
Well, the page you linked to is returning a 404 so I'm shooting in the dark here. Seems like you are trying to change the layout of some date. CSS does that sort of thing.
Feb 15, 2013 at 3:37 PM
Sorry, there was a comma in there: trying to get rid of the time
Feb 15, 2013 at 3:43 PM
Edited Feb 15, 2013 at 3:44 PM
You could override the template to render the DateTime value using a format string, e.g.
@myDateTimeValue.ToString("MMM dd yyyy")
Feb 15, 2013 at 5:05 PM
ok, so I create a template from ~/Core/Common/Views/Parts.Common.Metadata.Summary.cshtml, I am adding this to my views folder, its called

Here is the current code in my template: <div class="published">@Display.PublishedState(createdDateTimeUtc: Model.ContentPart.CreatedUtc, publisheddateTimeUtc: Model.ContentPart.PublishedUtc)</div>

What do I change?
Feb 15, 2013 at 5:15 PM
Edited Feb 15, 2013 at 5:15 PM
Well, it would depend on your exact requirements and I am not familiar with your theme, but you could replace the contents of that copied template with this:
<div class="published">@Model.ContentPart.PublishedUtc.ToString("MMM dd yyy"))</div>
The original template renders a shape called PublishedState, so you could choose to override that shape's template instead.
Again, it all depends on exact requirements and how you setup your theme.

Just keep in mind that you can completely customize the way things render by overriding templates.
Feb 15, 2013 at 5:17 PM
Edited Feb 15, 2013 at 5:18 PM
I should add that using format strings in this way may not be considered best practice, as it's not easily localizable. Instead you should either use DateTime methods such as ToShortDateString to take advantage of the date format associated with the current culture. Or, use the T method to render the format string, so you can potentially use PO files to localize the date formats.
Feb 15, 2013 at 5:32 PM
Well it worked thanks.