MVC DateTime Suffix HTMLHelper
Recently I have been working on an MVC Project, and tonight I got to the point where I wanted to output a date in a specific format, for example Tuesday 13th April 2010. Sadly DateTime formatting still doesn't allow you to specify output a suffix, you can do Tuesday 13 April 2010 but not what I wanted. I decided that I could achieve what I wanted by writing a quick HTMLHelper, this would then allow me to specify a datetime format string with a magic / special character which I could then replace for the appropriate suffix. Writing the helper was very quick and easy, if you want to learn about HTMLHelpers and how to write your own I recommend looking at Stephen Walther's Post on HTMLHelpers . The code for my datetimehelper is below: using System; using System.Web.Mvc; namespace mjjames.MVCHelpers { public static class DateTimeExtensions { public static string DateTimeFormat(this HtmlHelper helper, string dateTimeFormat, DateTime dateTime){ var dateTimeOutput =