Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Get Month Name from Month Number or vice versa

0.00/5 (No votes)
13 Jun 2012 2  
Get Month Name from Month Number or vice versa

We need a query to display month name and we have month number for that. Then firstly we create a switch case statement of if else statement for that. But we can get that easily by using the below code ..

int iMonthNo = 3; 
DateTime dtDate = new DateTime(2000, iMonthNo, 1); 
string sMonthName = dtDate.ToString("MMM"); 
string sMonthFullName = dtDate.ToString("MMMM"); 

And as well as if we have full name or half name of month and want to get month number, then we can use the code below ..

string sMonthName = "Jan"; 
sMonthName = "January"; 
int iMonthNo = Convert.ToDateTime("01-" + sMonthName + "-2011").Month; 

This is an optimized process for that in place of conditional statements..

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here