Solved

Convert a string to int

Posted on 2008-10-27
5
605 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

696 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