Change Date Format

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

If you look here: http://beta.taxtitleservices.com/news, 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?

Regards,
Tommy Havens
Coordinator
Feb 14, 2013 at 11:56 PM
CSS?
Feb 15, 2013 at 12:45 AM
Im not sure how CSS will change the format. Am I missing something?
Coordinator
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: http://beta.taxtitleservices.com/news trying to get rid of the time
Developer
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
~/Themes/TTS/Views/Parts.Common.Metadata.Summary.cshtml

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?
Developer
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.
Developer
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.