Solved

Convert a string to int

Posted on 2008-10-27
5
601 Views
Last Modified: 2010-04-21
I am trying to compare a date thats in a calendar with an int. I am actually calling the datetimenow function, so I need to convert this to an int. How do I do this?

The code snippet below gives the error:

CS0019: Operator '>' cannot be applied to operands of type 'int' and 'string'

I realise that I will need to convert the e.Cell.Text to an int also.

Thanks

private void calEvents_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)

    {

        DateTimeFormatInfo dformat = new DateTimeFormatInfo();

        dformat.MonthDayPattern = "dd MMMM yy";
 

        DateTime datetoday = DateTime.Now;
 

        string todaysdate = datetoday.ToString("m", dformat);
 

        string strgDay = todaysdate.Split(' ')[0];
 

        int dblDay = Convert.ToInt32(strgDay);
 

        Style style = new Style();
 

        if (dblDay > e.Cell.Text)

        {

            style.BackColor = System.Drawing.ColorTranslator.FromHtml("#666666");
 

        }
 

    }

Open in new window

0
Comment
Question by:CharlieDev
5 Comments
 
LVL 6

Assisted Solution

by:openshac
openshac earned 100 total points
ID: 22811263
Try:
int dblDay = datetoday.Day;

Open in new window

0
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 200 total points
ID: 22811280
           DateTimeFormatInfo dformat = new DateTimeFormatInfo();
            dformat.MonthDayPattern = "dd MMMM yy";

            DateTime datetoday = DateTime.Now;
            string todaysdate = datetoday.ToString("m", dformat);
            string strgDay = todaysdate.Split(' ')[0];
         

            int dblDay = Int32.Parse(strgDay);

            Style style = new Style();
            if (dblDay > e.Cell.Text)
            {
                style.BackColor = System.Drawing.ColorTranslator.FromHtml("#666666");
            }
0
 
LVL 13

Assisted Solution

by:kaylanreilor
kaylanreilor earned 200 total points
ID: 22811311
Can't you do something like this ?

      void DayRender(Object source, DayRenderEventArgs e)
      {

         if (e.Day.Date == calendar1.TodaysDate)
.......

calendar1 is the name of your calendar.
0
 

Author Comment

by:CharlieDev
ID: 22811389
Thanks, I think i have a flaw in my code. I still get the same error message,

 Operator '>' cannot be applied to operands of type 'int' and 'string'

Which means I'm totally stuck now. Could you try and help me with this, I wil post a new question as it is different to the original question I have just posted.
0
 

Author Closing Comment

by:CharlieDev
ID: 31510239
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

20 Experts available now in Live!

Get 1:1 Help Now