Compare system date with a date field in SQL
<p>I am trying to compare a date record in SQL Server with the system date. In my example the user first register with his name and date of birth which are then stored in the database. The user than logs into the web application using his name only. After logging in, his name is shown on the side where it says <code>"Welcome "player name</code>" using <code>Sessions</code>. </p>

<p>What I am trying to show in addition to his name is a message saying "happy birthday" if his date of birth matches the system date. I have tried working with <code>System.DateTime.Now</code>, but what I think is that it is also comparing the year, and what I really want is the day and the month only. I would really appreciate any suggestion or help. </p>

<p>CODE In Login page:</p>

<pre><code>protected void Button1_Click(object sender, EventArgs e)
{
  String name = TextBox1.Text;
  String date = System.DateTime.Today.ToShortDateString();
  SqlConnection myconn2 = new 
    SqlConnection(ConfigurationManager.ConnectionStrings["User"].ToString()); 

  SqlCommand cmd2 = new SqlCommand();
  SqlDataReader reader;

  myconn2.Open();
  cmd2 = new SqlCommand("Select D_O_B from User WHERE Username = @username", 
                        myconn2);
  cmd2.Parameters.Add("@username", SqlDbType.NVarChar).Value = name;
  cmd2.Connection = myconn2                           
  cmd2.ExecuteNonQuery();
  reader = cmd2.ExecuteReader();
  while (reader.Read().ToString() == date)
  {
    Session["Birthday"] = "Happy Birthday";
  }
}
</code></pre>

<p>Note: I using the same reader in the code above this one, but the reader here is with a different connection. Also, <code>reader.Read()</code> is different than <code>reader.HasRows</code>? </p>

<p>Code in Web app Page:</p>

<pre><code>string date = (string)(Session["Birthday"]); // Retrieving the session
Label6.Text = date; 
</code></pre>
