我想检索7天内所有记录,不知道时间参数在Delphi中怎么写,
把时间转换成字符串有问题。

解决方案 »

  1.   

    sql.clear;
    sql.add('select * from tablename where datefield between :BDate and :EDate');parambyname('BDate').AsDate := currentdate;
    parambyname('EDate').AsDate := currentdate - 7;
      

  2.   

    with Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add ('select field1 from ATable');
      SQL.Add ('where TimeField = :time');
      ParamByName('time').AsDateTime := FormatDateTime ('yyyy-mm-dd', ADateTimeTypeValue);//FormatDateTime()格式化成你所需要的日期格式,参考Delphi的在线帮助。
      Prepare;
      try
        Open;
        ....
        ....
      finally
        Close;
      end;
    end;
      

  3.   

    Query.active:=false;
    Query.SQL.clear;
    Query.SQL.Add('Select Clo From Table where date between '+''''+DateToStr(BeginDate)+''''+' and '+''''+ DateToStr(EndDate)+'''');
    Query.Active:=true;
      

  4.   

    DateTimeToString()            将日期时间格式转换为字符串 
    DateToStr()                   将日期格式转换为字符串 
    Time()                        返回当前的时间 
    TimeToStr()                   将时间格式转换为字符串 
      

  5.   

    使用结果报告:
      chutian(kiss you) 和wangchinaking(Deemon)的思路跟我想的一样,
    但行不通。SayForever(恒) 的意见没有问题。
    此贴到此为止。请各位注意接分。