« Home | Implemeting SSL in IIS 7.0 » | Maintain Scroll Position on PostBack in ASP.NET » | Offline Mode of your WebSite » | Handy Extension Methods for ASP.NET MVC's UrlHelper » | Credit Card Expiration Date DropDownList Sample Code » | Visual Studio Automatically Changing the IDs in So... » | Better Perfomance of Web Applications » | Display Numerals in Arabic Format » | The Controls collection cannot be modified because... » | Team Foundation PowerToys »

Month Name from Month Number

Getting Month Name from the Month Number is quite easy by extending DateTime properties in .net.

For Example, if you are having a month number, say 2, which you need to convert it into corresponding Month Name(February)




string strMonth = "2";

DateTime date = new DateTime(1, strMonth, 1);

string strMonthName = date.ToString("MMM");



This will return you the month name "Feb" ,but only first three characters.

If you need the month name in full, slightly modify the above syntax



string strMonth = "2";

DateTime date = new DateTime(1, strMonth, 1);

string strMonthName = date.ToString("MMMM"); // Four Characters will give you the full month name.



Happy Coding..

Labels: , , , , , , ,

Post a Comment