Link to home
Start Free TrialLog in
Avatar of siddhuoops
siddhuoops

asked on

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?

                   
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of siddhuoops
siddhuoops

ASKER

Cool..that worked. Thanks.
hi, i just thought giving a vs2008 version of this
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[2].ToString()