用参数
   query1.clear;
   query1.sql.add('where (rq>=:todate)and(rq<=:fromdate)and(spy='''+spyedit.text+''')');
   query1.parambyname('todate').asdatetime:=strtodate(edit1.text);
   query1.parambyname('fromdate').asdatetime:=strtodate(edit2.text);
   query1.prepare;
   query1.open;

解决方案 »

  1.   

    把日期直接相减,结果为double类型的值,晚的日期要比早的大,
      

  2.   

    TDateTime is a used by the date and time routines to hold date and time values.UnitSystemtype TDateTime = type Double;DescriptionMost VCL objects represent date and time values using the TDateTime type. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed. Following are some examples of TDateTime values and their corresponding dates and times:0 12/30/1899 12:00 am
    2.75 1/1/1900 6:00 pm
    -1.25 12/29/1899 6:00 am
    35065 1/1/1996 12:00 am
    To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive. 
    When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is ?.25, not ? + 0.25, which would be ?.75. There are no TDateTime values between ? and 0.Note: Delphi 1.0 calculated the date from year 1 instead of from 1899. To convert a Delphi 1.0 date to a TDateTime value in later versions of Delphi or in Kylix, subtract 693594.0 from the Delphi 1.0 date. The date format changed to be more compatible with OLE 2.0 Automation.
      

  3.   

    如果数据库中的begindate和enddate字段中存放了时分秒,应该这样做
    var
    date1:tdatetime;
    begin
    date1:=strtodatetime('2002-1-1 00:00:00');
    if (date1>adoquery1.filedbyname('begindate').asdatetime) and (date1<adoquery1.filedbyname('enddate').asdatatime) then
    begin
    /////////////////////////////////////////////
    end;
    end;