Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert month name to month number in C#

Posted on 2007-03-22
3
Medium Priority
?
17,705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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