Solved

convert month name to month number in C#

Posted on 2007-03-22
3
16,976 Views
Last Modified: 2010-05-19
Hello experts,

                   I am using a label to get the month name(Jan, Feb, Mar.....) using this line of code.
if (month > 12) month = month - 12;
        lblMonth.Text = String.Format("{0:MMMM}", DateTime.Parse(month.ToString() + "/01/1900"));

Now, how would I compare the month name in a label to the number(like 1 for Jan, 2 for Feb, 3 for Mar)..I just want to make some textboxes readonly by comparing the current month with the month name in the label.

I tried;
if (DateTime.Now.Month == Convert.ToDate(lblMonth.Text)
{
    //then do this
}

But I am not doing the casting right. Could someone please help?

                   
0
Comment
Question by:siddhuoops
3 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 18772302
try

if (DateTime.Now.Month == Convert.ToDate(lblMonth.Text + " 01, 1900").Month)
{
    //then do this
}

0
 

Author Comment

by:siddhuoops
ID: 18772347
Cool..that worked. Thanks.
0
 
LVL 14

Expert Comment

by:Jai S
ID: 20821150
hi, i just thought giving a vs2008 version of this
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[2].ToString()
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now