with query do
  begin
    close;
    Sql.clear;
    Sql.add('select * from table where date<=:date1 and date>=date2');
    parameters[0]:=datetimetostr(datetime1.date);
    parameters[1]:=datetimetostr(datetime2.date);
    open;
  end;

解决方案 »

  1.   

    先把日期变成整数。在用sql查询完毕,再转化回来。
      

  2.   

    DateTimeToStr跟区域设置中有关系,所以建议不要使用
    with query do
      begin
        close;
        Sql.clear;
        Sql.add('select * from table where date<=:date1 and date>=date2');
        ParamByName('Date1').AsString :=FormatDateTime('yyyy-mm-dd',Datetime1.Date);
        ParamByName('Date2').AsString :=FormatDateTime('yyyy-mm-dd',Datetime2.Date);
        open;
      end;
      

  3.   

    select * from table where datatime1 > date and date < datatime2没有测试过。你自已去试吧
      

  4.   

    var
      VarStr:String;
    with query do
      begin
        VarStr:='select * from table where date<="'+DateTime1.Date+'"'+' and  date>="'+DateTime1.Date+'"';
        close;
        Sql.clear;
        Sql.add(VarStr);
        open;
      end;
      

  5.   

    with Query do begin
      SQL.Text:='select * from table where date<= '''+
    FormatDateTime('yyyymmdd',Datetime1.Date)+''' and date>= '''+
    FormatDateTime('yyyymmdd',DateTime2.Date)+'''';
      open;
    end;
      

  6.   

    同意wolfAone(¤一步一步网上爬¤) , DateTimeToStr跟区域设置中有关系.SqlStr := Format('select * from YourTable where YourDate between %s and %s',[FormatDateTime('yyyy-mm-dd',Datetime1.Date),FormatDateTime('yyyy-mm-dd',Datetime2.Date)]);
      

  7.   

    在sql 里面, 有没有将字符转换为日期的函数。 因为我字段是定义为char类型, 所以如果进行比较的话,02-1-3
    02-1-1
    02-1-15如果有这三条记录,
    按照字符查找的话, 
    where date>='02-1-1' and date<='02-1-15'  应该是上面的三条全都满足。执行这条语句就显示 
    02-1-1
    02-1-15
    这两条记录。
    02-1-3就没有显示了。
      

  8.   

    with query do
      begin
        close;
        Sql.clear;
        Sql.add('select * from table where date>=:begindate and date<=:enddate');
        parameters[0]:=datetimetostr(datetime1.date);
        parameters[1]:=datetimetostr(datetime2.date);
        open;
      end;