Solved

Convert a string to int

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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