Select * From Table1 Where 当前日期-借书日期<=30

解决方案 »

  1.   

    select * from table1
    where Datediff(day,d1,getdate())<=30
      

  2.   

    测试完毕:
    select * from table1
    where Datediff(day,convert(smalldatetime,sdate),getdate())<=30 
    其中sdate就是你的日期字段(字符类型)
      

  3.   

    to afeisky(刀光剑影(离开xkx@MUD的日子)), 不知Datediff是个什么函数,如何使用
      

  4.   

    没看错?人家的字段是字符型的,应该转换一下。able: 把数据库类型告诉大家一下,把字段格式也说一说。
      

  5.   

    select * from table1
    where Datediff(day,convert(char(12),fdate),getdate())<=30 
    其中convert是转换函数,fdate就是你的借书日期(字符类型)
      

  6.   

    感谢各位,马上有分赠送。数据库类型是paradox.格式:2001-09-28
      

  7.   

    select * from table1
    where Datediff(day,d1,:date)<=30
    Table.ParmatByName('date').AsDate:=........
    没式过但感觉可以
      

  8.   

     上面各位大虾,上述方法不能通过,提示invalid use of keyword,好象是getdate和convert的问题;
    不知下面的语句为什么不行,提示 getdate和convert没有定义;query1.SQL.Add('select * from jsqk where datediff(day,:f,:e)<=30');
       query1.ParamByName('e').AsDateTime:=getdate();
      query1.ParamByName('f').AsDateTime:= convert(smalldatetime,借书日期);
      

  9.   

    query1.ParamByName('e').AsDateTime:=getdate();
    应该是
    query1.ParamByName('e').AsDate:=getdate();
      
      
      

  10.   

    query1.ParamByName('f').AsDateTime:= convert(smalldatetime,借书日期); 呵呵,convert是SQL Server的函数,在Delphi中行不通的。可以这样:
    query1.sql.text := 'select * from jsqk where '+FormatDateTime('mm"/"dd"/"yyyy', Date)+'-cast( "借书日期" as Date )<=30';
    query1.open;条件是:借书日期的格式必须是:yyyy/mm/dd,或者跟BDE日期格式设置有关系。
      

  11.   

    to agui(阿贵) 上面的方法通不过,"type mismatch in expression"
    能不能帮我用参数的方法解决? 非常感谢
      

  12.   

    改成
    query1.sql.text := 'select * from jsqk where "'+FormatDateTime('mm"/"dd"/"yyyy', Date)+'"-cast( "借书日期" as Date )<=30';
    我少了引号“借书日期”字段我还不知道是否能行,因为我没有用过汉字字段名。用参数没有多大差别,我试试吧。把你的数据库寄给我:[email protected]
      

  13.   

    delphi中TDateTime就是双精度浮点类型,其中小数点以前表示当天与公元1900年1月1日的差,你可以用floattoint(today)-floattoint(yourdate)求出时间差,单位是天。