Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
between two dates, I want to paint red. sample code as follows.

C#
for (int i = 1; i < 32; ++i)
            {
                btn = new Button();
                btn.Size = new Size(30, haftaLENGHT);
                btn.Text = i.ToString();
                temmuzflowlayout.Controls.Add(btn);
                btn.FlatStyle = FlatStyle.Popup;
                for (int k = 0; k < dataGridView1.RowCount; k++)
                {
                    tarih = dataGridView1.Rows[k].Cells[4].Value.ToString();
                    tarih2 = dataGridView1.Rows[k].Cells[5].Value.ToString();

                    if (tarih.ToString() != "")
                    {
                        if (tarih.Substring(6, 4) == m_yıl.Text)
                        {
                            if (tarih.Substring(3, 2) == "07")
                            {
                                if ((tarih.Substring(0, 2) == btn.Text)||(tarih2.Substring(0,2)==btn.Text))
                                {
                                    btn.BackColor = Color.Red;
                                }
                            }
                        }
                    }
                }
            }
Posted
Updated 1-Apr-11 3:54am
v2
Comments
Henry Minute 1-Apr-11 10:06am    
Does the code you have posted not work?

Give us a clue, for goodness sake.

Assuming the two values being retrieved from the dataset are dates, this is the way I'd do it (untested code):

C#
for (int ...)
{
    tarih1 = dataGridView1.Rows[k].Cells[4].Value.ToString();
    tarih2 = dataGridView1.Rows[k].Cells[5].Value.ToString();
    DateTime tarihDate1;
    DateTime tarihDate2;
    if (DateTime.TryParse(tarih1, out tarihDate1) && DateTime.TryParse(tarih2, out out tarihDate2))
    {
        // we have valid dates, so we can continue processing)
        // I have no idea what criteria causes the button to be red, but 
        // here's some sample code that uses the parsed dates - If the 
        // dates are within 7 days of each other, the button background 
        // is changed to red
        TimeSpan span = tarihDate2 - tarihDate1;
        if (span.Days == 7)
        {
            btn.BackColor = Color.Red;
        }
    }
}


Go forth, and code.
 
Share this answer
 
DateTime dt = wherever you get this from,
  startTime = the start of the time period,
  endtime = the end of the time period;
if((dt >= startTime) && (dt < endTime)) myButton.BackColor = Color.Red;


Your question is very unclear and your code is not clear enough to work out what exactly you are trying, but that is how you test dates in C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900