ACCESS数据库中有字段id(数字型),date(日期型,yyyy-mm-dd hh:nn:ss),
id  date
1    2005-6-1 13:12:12
2    2005-6-2 12:12:34
3    2005-6-2 12:14:34
比如今天是6月2日,如何查找今天的数据条数?
select count(id) from table where date=Now() 有错误!

解决方案 »

  1.   

    "select count(id) from table where date=#"&Now()&"#"
      

  2.   

    不是吧,NOW()得出的结果是当前时间,精确到秒的.这样查找出来的结果肯定是0条
      

  3.   

    select count(id) from table where convert(char(10),date,120)=convert(char(10),getdate(),120)
      

  4.   

    你这个查询语句在那个里面写的?
    要是c#里面的话
    exestr="select count(id) from table where date='"+
    System.DateTime.Now.Date.ToString()+"'";要是写在sql server里面的话
    select count(id) from table where date=CURRENT_TIMESTAMP
      

  5.   

    select count(id) from table where date=getdate()
      

  6.   

    都不对,
    exestr="select count(id) from table where date='"+
    System.DateTime.Now.Date.ToString()+"'";
    提示类型不匹配!我数据库中的类型是yyyy-mm-dd hh-nn-ss,而System.DateTime.Now.Date.ToString()是string型,换成System.DateTime.Now.Date页不对select count(id) from table where date=getdate()
    提示找不到getdate()
      

  7.   

    select * from table where convert(varchar(8),datecolumn,111) = convert(varchar(8),getdate(),111)
      

  8.   

    正解
    select count(id) from table where datepart("d",date)=datepart("d",Now())
      

  9.   

    select count(id) from table where datepart("d",date)=datepart("d",Now())
    这样查找出来的数据显然不对,今天是2005-6-3,那么它还会把2005-5-3,2003-6-3满足的都找出来
      

  10.   

    "select count(id) from table where date like '" & date() & "'"
    试试!
      

  11.   

    dt=System.DateTime.Now;
    "select count(id) from table where date like '_"+dt.year+"-"+dt.Month+"-"+dt.Day+"_'";
      

  12.   

    string  strSel = "select count(id) as today_reply from reply where datepart('yyyy',date)=datepart('yyyy',Now()) and datepart('m',date)=datepart('m',Now()) and datepart('d',date)=datepart('d',Now())"; 
    这个是正确的,但是感觉很繁琐.有没有简单一点的查询.下面这条查出来数据是0,为什么? 看样子like在这里行不通
    string today = System.DateTime.Now.ToString("yyyy-M-d");
    string  strSel = "select count(id) as today_reply from reply where date like '" + today + "'";
      

  13.   

    DateTime tempTime = Convert.ToDateTime("2005-6-2 12:12:12");
    string sql = "select count(id) as today_reply from reply where date between '" + tempTime.ToShortDateString() + "' and '" + tempTime.AddDays(1).ToShortDateString() + "'";
    试一下
      

  14.   

    一个很好的解决方法是:        date>今天 and date<明天的时间   我一直都在用.
      

  15.   

    转换成字符串比较:
    select count(id) from table where
    CONVERT(char(12),[date], 2) = CONVERT(char(12),getdate(), 2)