数据库 表table 中有个日期型字段:d_date  (代表一个还书时间,'2009-10-10')
我想把表中 还书时间小于当前时间的记录选择出来。
select * from table where datediff('dd',d_date,getdate())<0
这样达不到想要的效果,请大家指教下。

解决方案 »

  1.   

    select * from table where d_date<getdate()
      

  2.   

    我第一次用<号作出比较,但是也没用。。别人说要要用datediff才能比较。。
      

  3.   

    select * from table where datediff(day,d_date,getdate()) >0 
      

  4.   

    正如楼上所说- -
    2楼你所说的情况
    多半是格式有问题
    先2话不说把d_date格式化下吧
    select * from table where convert(varchar(10),d_date,111)<convert(varchar(10),getdate(),111)
      

  5.   

    我刚查看了数据库时间记录 d_date字段有个数据2009-2-9,我记得正确的格式应该是2009-02-09吧?
      

  6.   

    突然发现数据库是acceess的,应该怎么样做呢?d_date是日期型。
      

  7.   

    实在抱歉,由于是帮人修改,细节注意不够,我已经用习惯了MS SQL,一下没反应过来。
    查了下文档aceess应该是:WHERE datediff('d',d_data,now())<=0
      

  8.   

    ACCESS也一样。
    直接 select * from table where d_date<now()