?
Solved

Convert a string to int

Posted on 2008-10-27
5
Medium Priority
?
617 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
[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
5 Comments
 
LVL 6

Assisted Solution

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

Open in new window

0
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 800 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 800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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