select * from table where time='2008-12-25 0:00:00 '
从外面接收来的时间是'2008-12-25 0:00:00 '这样的形式,数据库是的时间格式也是同样的,只是一天中的0:00:00 不同,我现在想把从外面接收来的时间,比如是'2008-12-25 0:00:00 ',匹配数据库中2008-12-25这一天所有的数据,怎么做啊??望指教~~

解决方案 »

  1.   

    datediff函数
    where DateDiff(day,time,'2008-12-25') = 0
      

  2.   

    select * from table where time>='2008-12-25 00:00:00' and time<='2008-12-25 23:59:59 '或者
    select * from table 
    where
    datepart(yyyy,time)=2008 and 
    datepart(mm,time)=12 and 
    datepart(dd,time)=25
      

  3.   

      DateTime _Time = DateTime.Parse("2008-12-25 0:00:00");
    1 大于 小于
    "select * from table where time >='"+_Time.ToString("yyyy-MM-dd")+" 0:00:00 '
     and time<="+_Time.ToString("yyyy-MM-dd")+" 23:59:59'";
      

  4.   

    楼上说的是,我的
    select * from table where time='"+txtCase.Text.ToString()+"',时间是从这里接收的,在文本框里时间的选择是用一个JS做的,获得的时间格式是'2008-12-25 00:00:00' 这样的,我现在想从数据库中查找2008-12-25这一天所有的记录,请问怎么做啊??
      

  5.   


    select * from table where DateDiff(day,time,'"+txtCase.Text.ToString()+"') = 0
    就是获得一天的啊
      

  6.   


    select * 
    from tb 
    where convert(varchar(10),[time],120)='"+txtCase.Text.ToString("yyyy-MM-dd")+"'
      

  7.   


    select * 
    from tb 
    where convert(varchar(10),[time],120)='"+DateTime.Parse(textBox1.Text).ToString("yyyy-MM-dd")
    +"'
      

  8.   

    select * 
    from tb 
    where convert(varchar(10),[time],23)='"+DateTime.Parse(textBox1.Text).ToString("yyyy-MM-dd") 
    +"'convert(varchar(10),[time],120) 返回的是 2009-03-16 14:09:00
      

  9.   


    注意这个varchar(10),所以只有前10位... 
      

  10.   

    if @publishdate IS NOT NULL and @publishdate<>''
    begin
    set @sqlStr=@sqlStr+' and PublishDate>='''+Convert(varchar(10),@publishdate,120)+''' and PublishDate<'''+Convert(varchar(10),@publishdate+1,120)+''''
    end
    根据上面改一下试试!我这是写在存储过程里面的!