Tuesday 12 August 2014

Display Date Suffix in C#

private string GetDateSuffix(string day)
{
    string strDatesuffix = "th";
    if (int.Parse(day) < 11 || int.Parse(day) > 20)
    {
        day = day.ToCharArray()[day.ToCharArray().Length - 1].ToString();
        switch (day)
        {
            case "1":
                strDatesuffix = "st";
                break;
            case "2":
                strDatesuffix = "nd";
                break;
            case "3":
                strDatesuffix = "rd";
                break;
        }
    }
    return strDatesuffix ;
}

No comments:

Post a Comment