convert month name to month number in C#

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?

Who is Participating?
dstanley9Connect With a Mentor Commented:

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

siddhuoopsAuthor Commented:
Cool..that worked. Thanks.
Jai STech ArchCommented:
hi, i just thought giving a vs2008 version of this
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.