Click here to Skip to main content
Click here to Skip to main content

Get Month Name from Month Number or vice versa

, 13 Jun 2012
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Technoses
Software Developer (Senior) Super Eminent Softwares
India India
My name is Peeyush Shah and I am working with Microsoft.Net Framework at Jaipur, India with a Taxaction Software Development Company Named Professional Softec Pvt. Ltd.
 
My main focus is the development of online application.
We also develop custom software solutions for our customers and are able to support developers in using the following technologies, because we use them every day

- .NET Framework 2.0
- C#
- ASP.NET
- ASP.NET AJAX
- SQL Server 2005
- ADO .NET
- XML Webservices
- Payment systems

Feel free to take a look at the website and see Microsoft's new technologies in action
Group type: Organisation

7 members


Comments and Discussions

 
QuestionExtension Methods PinmemberMatt U.13-Jun-12 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 13 Jun 2012
Article Copyright 2012 by Technoses
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid