str1:=FCbYear1.Text+'-1-1';
str2:=IntToStr(StrToInt(FCbYear1.Text)+1)+'-1-1';
Date_Range:=' and (B.Paytime>=#'+str1+'# and B.Paytime<#'+str2+'#) ';从文本组件中获得年数,然后添加‘-1-1’作为月和日
再把所得到的时间作为sql查询的条件
但是结果好像查询的时候str1和str2的值都是随机的实数
是不是因为没有把str1转换成date型所致阿?我试过strtodatetime,不行呀
说incompatible types:'string'and 'TDateTime'
应该怎么做啊

解决方案 »

  1.   

    strtodatetime('2005-01-01')  没问题的啊
      

  2.   

    是你的系统日期分隔符不是'-'所致,你需要用与你系统日期分隔符来代替'-'
    你也可以用
    VarToDateTimeConverts a specified variant to a TDateTime value.UnitVariantsCategoryVariant support routinesDelphi syntax:function VarToDateTime(const V: Variant): TDateTime);C++ syntax:extern PACKAGE TDateTime __fastcall VarToDateTime(const Variant &V);DescriptionVarToDateTime converts the given variant to a TDateTime value. VarToDateTime raises an exception if the conversion fails.