Remove Time Part and Match only Date in SQLServer

Last Reply on Dec 01, 2012 06:53 AM By Mudassar

Posted on Dec 01, 2012 06:39 AM

i want to search record using dropdown and text box 

the data type is DateTime

in date column its saving as 28/11/2012 12:45:08  full date and time 

 

i am using this code its not working on client systems . its only working on server 

urgent please rply 

 

 protected void Button2_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions WHERE report_type = @report_type AND " + "[R_date] >= @date_t_s and [R_date] < @date_t_e");

        cmd.Connection = con;
        cmd.Parameters.Add("@report_type", SqlDbType.NVarChar).Value = DropDownList1.SelectedValue;
        cmd.Parameters.Add("@date_t_s", SqlDbType.DateTime).Value = DateTime.Parse(TextBox1.Text);
        cmd.Parameters.Add("@date_t_e", SqlDbType.DateTime).Value = DateTime.Parse(TextBox1.Text).AddDays(1);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
}

 

You are viewing reply posted by: Mudassar on Dec 01, 2012 06:53 AM.
Posted on Dec 01, 2012 06:53 AM

This way

declare @date_t_s Datetime

set @date_t_s = '2012-12-01 08:00:00.810'

declare @Emp table(Name varchar(10), [date] datetime)

insert into @Emp
select 'A', '2012-12-01 18:49:00.810'
union all
select 'B', '2012-06-01 09:49:11.810'
union all
select 'C', '2012-12-01 11:49:22.810'
union all
select 'D', '2011-01-01 18:49:17.810'
 
SELECT * FROM @Emp where CONVERT(Varchar(12),[date], 3) = CONVERT(Varchar(12),@date_t_s, 3)