Sunday, 13 October 2013

how to get date format like 6th using c#?

Hi in this post i will explain how to get date format like "6th sep" using c#

by sending the date field value the following function evaluates the date current date extention will it returns..

by using the following method.

public static string ToOrdinal(int number)
        {
            switch (number % 100)
            {
                case 11:
                case 12:
                case 13:
                    return number.ToString() + "th";
            }

            switch (number % 10)
            {
                case 1:
                    return number.ToString() + "st";
                case 2:
                    return number.ToString() + "nd";
                case 3:
                    return number.ToString() + "rd";
                default:
                    return number.ToString() + "th";
            }
        }

      public static string GenerateDateString(DateTime value)
        {
            return string.Format(
                "{0} {1:MMMM}",
                ToOrdinal(value.Day),
                value);
        }


by this way it will returns the date format as follows

"ex: 6th , 22nd, 1st etc..."

No comments:

Post a Comment