Reshma
Reshma

Reputation: 1430

Filter a DataTable using Date value?

I want filter data table using date and display in grid view. Given below is my code, but its not showing any result in gridview. I am passing this 03/18/2015 date.

Sample DB :

SlNo   Name   Submited_Date
----  ------  -------------
1      abc    3/18/2015 6:24:48 PM
2      xyz    3/18/2015 6:48:23 PM
3      pqr    3/20/2015 3:14:18 AM

Code :

protected void btnSubmit2_Click(object sender, EventArgs e)
{
CommunicationTableAdapters.tbl_splited_detailsTableAdapter sd;
sd = new CommunicationTableAdapters.tbl_splited_detailsTableAdapter();
DataTable dt = new DataTable();
dt = sd.GetSiteDetails(Convert.ToDateTime(txtDate.Text));
GridView1.DataSource=dt;
GridView1.DataBind();
}

SQL :

GetSiteDetails:

SELECT        SlNo, Name, Submited_Date
FROM          tbl_splited_details
WHERE         (CONVERT(DATETIME, Submited_Date) = @date)

Upvotes: 0

Views: 61

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460068

So you want to ignore the time portion of the DateTime?

If you use SQL-Server 2008 or higher you can convert the datetime to date:

SELECT        SlNo, Name, Submited_Date
FROM          tbl_splited_details
WHERE         (CONVERT(DATE, uploaded_date) = CONVERT(DATE, @date))

Upvotes: 5

Related Questions