Mega Code Archive

 
Categories / C# / Date Time
 

Gets the ordinal suffix for a given date

using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Xml; class Main{     ///<summary>     /// Gets the ordinal suffix for a given date     ///</summary>     ///<param name="date">The date</param>     ///<returns>The ordinal suffix</returns>     private static string GetDayNumberSuffix(DateTime date)     {       switch (date.Day)       {         case 1:         case 21:         case 31:           return @"\s\t";         case 2:         case 22:           return @"\n\d";         case 3:         case 23:           return @"\r\d";         default:           return @"\t\h";       }     }      }