我有一个MSSQL数据库,里面有一个表,表中一个字段是datetime类型的,在select语句中如何根据这个时间来查询,用C#来写,希望各位高手给我个例子,谢谢

解决方案 »

  1.   

    declare @tb table (sj datetime)
    insert into @tb select '2007-03-02'select * from @tb where sj between '2009-10-02' and '2009-10-02 23:59:00'
      

  2.   

    select * from tb where convert(varchar,sj,120)='2009-10-24'
      

  3.   


    SqlConnection myConn = new SqlConnection(strConnection);
    SqlDataAdapter sqlda = new SqlDataAdapter("select * from TableName where 启动时间> '2009-10-25 01:12:12' ", myConn);
    DataTable dt = new DataTable();
    sqlda.Fill(dt);
    dataGridView1.DataSource = dt;
      

  4.   

    string strSql=" select * from table where time between to_date('2009-10-02 0:00:00','yyyy-mm-dd hh:mi:ss') and to_date('2009-10-02 23:59:59', 'yyyy-mm-dd hh:mi:ss') ";
    其中的时间为你想要的时间范围起始点,在时间后面需要给其定义格式
      

  5.   

    convert(varchar,sj,112)='2009-10-24' 多种 时间格式可以使用,比如110,120,等具体可以查查,