Format a datetime field

Jan 3, 2015 at 1:57 AM
I have a DateTime field in a content type, and @content.MyField produces: 12/1/2014 12:00:00 AM

I'd like to produce "December 1, 2014" ... so how do I do this easily?
Jan 3, 2015 at 12:48 PM
@content.MyField is of type DateTime. so you have to convert it to a string.

A DateTime has a property 'Date' which provides you some convert-to-string methods.

since @content.MyField is dynamic you might loose intellisense so use a typed datetime in your template to play around.
  @{
        var myDate = DateTime.Now;
    }


    <p>
        @myDate.Date.ToString("dd MMM yyyy");
         //@content.MyField.Date.ToString("dd MMM yyyy");
    </p>   
about formatsyntax:
http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx


hope this helps a little bit.

greetz
collective
Marked as answer by jncraig on 1/4/2015 at 9:32 AM
Jan 4, 2015 at 5:32 PM
Thanks.