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.ToStr ing() + "/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.Te xt)
{
//then do this
}
But I am not doing the casting right. Could someone please help?
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.ToStr
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.Te
{
//then do this
}
But I am not doing the casting right. Could someone please help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi, i just thought giving a vs2008 version of this
System.Globalization.Cultu reInfo.Cur rentCultur e.DateTime Format.Mon thNames[2] .ToString( )
System.Globalization.Cultu
ASKER