Solved

Convert a string to int

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
import issue in bit values 3 44
visual Basic Net vs c# net 8 56
cs.Designer Issue 2 20
ASP.NET Web API or ASP.NET Core MVC? 3 32
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

9 Experts available now in Live!

Get 1:1 Help Now