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..
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: .net2.0, .net3.5, conversion, datetime, functions, microsoft, month, visual studio
Post a Comment