有一个办法把日期当作浮点数来处理

var
  D1,D2,Ssql:String;
  Date1,Date2:TDate;
Begin
D1:=FloatToStr(Date1-1);
D2:=FloatToStr(Date2);
sSql:='select * from Tabel where 日期字段 Between '+D1+' and '+D2;.....
Sql.Add(ssql);
....
end;

解决方案 »

  1.   

    SQL.Add(' Select * From Table1')
    SQL.Add(' Where Date >='+#39+Edit1.Text+#39);
    不是就可以了吗??
      

  2.   

    可以考虑,但不理想,我以前用过别人的组件(结合woll2woll公司的),通过一个临时的clientdataset(不applyupdate)将结构传过去,和tstring一样用查询,真的简单,但是现在没有组件了, 真的麻烦!
      

  3.   

    我写过:
    源码如下:
    //++++++++++++++++++++++++++++++++++++++++++++
    // 功能:将Delphi的日期格式转化为SQL的日期格式
    // 参数:
    //      dDate:Delphi的日期
    // 返回值:返回SQL的日期字符串
    //++++++++++++++++++++++++++++++++++++++++++++
    Function GetSQLDate(dDate:TDateTime):string;
    var
        Year, Month, Day: Word;
    begin
        DecodeDate(dDate, Year, Month, Day);
        result:=inttostr(Month)+'/'+inttostr(Day)+'/'+inttostr(Year);
    end;
      

  4.   

    ///////////////////////////////////////////
    // 功能:  获得指定日期所在月的天数
    // 参数:
    // dDate: 指定日期
    // 返回值:返回天数
    // 日期:2001/8/11
    ///////////////////////////////////////////
    function GetMonthMaxDay(dDate:TDate):integer;
    var
        Yr, Mnth, Day: Word;
    begin
        DecodeDate(dDate, Yr, Mnth, Day);
        case Mnth of
        1,3,5,7,8,10,12:
            Result:=31;
        4,6,9,11:
            Result:=30;
        2:
        begin
            if IsLeapYear(Yr) And (Mnth=2) then
                result:=29
            else
                result:=28;
        end;
        else
            result:=0;
        end;
    end;
      

  5.   

    ////////////////////////////////////////////////////////
    // 功能:把 SQL(字符串) 的日期该为Delphi的日期(TDate)
    // 参数
    // SQLDate: SQL 的日期(类似:6/23/2001)
    // 返回值:返回 Delphi 的日期
    // 日期:2001/6/21
    ////////////////////////////////////////////////////////
    Function Sql2DelphiDate(SQLDate:string):TDate;
    var
        Year,Month,Day:Word;
        i:integer;
    begin
        Year:=strtoint(myRight(SQLDate,4));
        i:=pos('/',SQLDate);
        Month:=strtoint(myLeft(SQLDate,i-1));
        Day:=strtoint(Copy(SQLDate,i+1,2));
        result:=EncodeDate(Year,Month,Day);
    end;//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // 功能:将Delphi的日期格式转化为短日期格式
    // 参数:
    //      dDate:Delphi的日期
    // 返回值:返回断日期字符串
    //++++++++++++++++++++++++++++++++++++++++++++
    Function GetShortDate(dDate:TDateTime):string;
    var
        Year, Month, Day: Word;
    begin
        DecodeDate(dDate, Year, Month, Day);
        result:=Copy(inttostr(Year),3,2)+'.'+inttostr(Month)+'.'+inttostr(Day);
    end;
      

  6.   

    ...
    where to_date('2001-10-1 12:12:12','yyyy-mm-dd hh24:mi:ss')