Including a Day Suffix when formatting a Date in C#

Posted on Saturday, July 5, 2014 at 11:17 PM into csharp & code by Steve Woods.
Roughly a 1 minute read.

One formatting option for the DateTime object in C# that is missing is the ability to display the correct suffix for a given date, as in 4th January - Usually the best you can hope for is something like 4 January which looks crap.

Here's a quick extension method I've written which will automatically calculate it for you and allow you to format the date as normal.

The Code


Call the code like this:

DateTime myDate = new DateTime(2000,1,1,0,0,0);
Debug.Print(myDate.ToStringWithSuffix("dd[$suffix] mmm yyyy"));

Job done :)






Please consider what you post!
Chillax if you're angry.