Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:56:52+00:00 2026-06-01T21:56:52+00:00

I am trying to compare a date record in SQL Server with the system

  • 0

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 "Welcome "player name” using Sessions.

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 System.DateTime.Now, 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.

CODE In Login page:

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";
  }
}

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

Code in Web app Page:

string date = (string)(Session["Birthday"]); // Retrieving the session
Label6.Text = date; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:56:53+00:00Added an answer on June 1, 2026 at 9:56 pm

    You can replace the code fragment to compare date above with this one

    object dobVal = null;
    while ((dobVal= reader.Read()) != null)
    {
      var storedDob = Convert.ToDateTime(dobVal.ToString());
    
      if(storedDob.Month == DateTime.Now.Month && 
         storedDob.Day == DateTime.Now.Day)
      {
        Session["Birthday"] = "Happy Birthday";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey i am trying to compare the date on which the user opens the
I am trying to compare a date in SQL and create a new field
Im trying to compare a specific date periodDate which is stored in a xml
I am trying to compare two text files and output the first string in
Via a stored procedure in SQL Server 2008 , I am trying to show
I'm trying to compare just the date of a column but because the query
I'm pretty new to the jquery validation plugin. Trying to compare date values in
I am trying to compare two dates which are in Finnish time form like
I'm trying to compare a GMT time offset from the operating system to a
I am trying to force a user to select a date in the future

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.