how to compare date(database(sql server 2005)) to datetime.today( C#)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jhayss
    New Member
    • Dec 2014
    • 1

    how to compare date(database(sql server 2005)) to datetime.today( C#)

    I'm making a hotel booking system, and I want to make a background color change in my button(dependin g on the date)

    When the date value in database is equals to today the color should be red.. but if its not today the background color should be yellow but if its not being booked it should be Green..

    I'm using this code:
    Code:
      while (dr.Read())
                {
                    DateTime now = DateTime.Today;
               now = Convert.ToDateTime(datetoday.Value);
                 
                 DateTime a = Convert.ToDateTime(dr[1]);
    
                 if (a != now && a == now)
                    {
                        room1.BackColor = Color.Red;
                    }
                 if (a != now)
                 {
                     room1.BackColor = Color.Yellow;
                 }
                    if (a == now)
                    {
                        room1.BackColor = Color.Red;
                    }
    
                }
                dr.Close();
    The yellow color will run but the red color won't activate... am I missing something?
    Last edited by Frinavale; Dec 5 '14, 02:34 PM. Reason: Added code tags and fixed grammar.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The value of Now includes the date and the time.

    Consider comparing just the date portion to the date retrieved from the database.

    -Frinny

    Comment

    Working...