How to compare date from database using C#?
Posted
by
user1490374
on Stack Overflow
See other posts from Stack Overflow
or by user1490374
Published on 2012-09-04T03:25:52Z
Indexed on
2012/09/04
3:38 UTC
Read the original article
Hit count: 103
c#
|sql-server-2008
I would like to compare the date selected from the database (every entry in EndDate) and compare them with today date. Is there any way to do this programmatically? Like extracting the dates and comparing them individually? I need this because I need to update the status for the table.
string username;
username = HttpContext.Current.User.Identity.Name;
string date = DateTime.Now.ToString("MM/dd/yyyy");
txtDate.Text = date;
SqlConnection conn1 = new SqlConnection("Data Source=mydatasource\\sqlexpress;" + "Initial Catalog = Suite2; Integrated Security =SSPI");
SqlDataAdapter adapter;
string end;
end = "SELECT EndDate FROM Table_Message WHERE username = '" + username + "'";
adapter = new SqlDataAdapter(end, conn1);
conn1.Open();
DataSet ds = new DataSet();
adapter.Fill(ds);
//Execute the sql command
GridView2.DataSource = ds;
GridView2.DataBind();
conn1.Close();
© Stack Overflow or respective owner