I find it intersting that the MS did not have this by default as part of the Standard DateTime Format Strings for .NET.
So I did my own thing..
public static string FormatDateTime(DateTime date)
{
return String.Format("{0:dddd}, {1} {0:MMMM} {0:yyyy}", date, AppendDaySuffix(date.Day) );
}
public static string AppendDaySuffix(int day)
{
string daySuffix = "";
if (day == 1 || day == 21 || day == 31)
daySuffix = "st";
else if (day == 2 || day == 22)
daySuffix = "nd";
else if (day == 3 || day == 23)
daySuffix = "rd";
else
daySuffix = "th";
return (day + daySuffix);
}
You can download a good pdf reference for .NET DateTime formats from
http://john-sheehan.com/blog/wp-content/uploads/msnet-formatting-strings.pdf
Advertisement
Filed under: Technical
Thanks for the link…this code would make a great extension method. Nice work.
No Problem, Nice work on the cheat sheet..;)
good work, thats saved me a lot of time! cheers
Thanks a lot! It is odd that Microsoft didn’t include this.