关于daysbetween函数
我在delphi中直接调用daysbetween函数的时候,老是提示没有定义这个函数。我看资料这是delphi中的函数,为什么不能直接用

解决方案 »

  1.   

    缺少单元;你要看Unit 是什么,要加入到代码的 uses 部分
      

  2.   

    要找这些单元的简单方法是打开你的delphi 安装目录,然后进入source 子目录,并且搜索文件内容,把你的函数名作为搜索条件,即可找到;然后加入有该函数的单元名称于你的代码的uses部分。
      

  3.   

    Uses
      DateUtils;
      

  4.   

    我实了,可以,但并不是实际的差值:如:inttostr(DaysBetween(now(),2004-6-4))
    的到的结果是10天,请教一下这是怎么回师
      

  5.   

    不会吧,我这边是好的
    要不楼主改为:
    inttostr(trunc(now)- trunc(2004-6-4))
      

  6.   

    Call DaysBetween to obtain the difference, in days, between two TDateTime values.DaysBetween counts only whole days that have elapsed. Thus, DaysBetween reports the difference between Dec 31, 1999 11:59 PM and Jan 1, 2000 11:58 PM as 0 because the difference is one minute short of an entire day.
      

  7.   

    inttostr(DaysBetween(now,strtodate('2004-6-4')))
    或者
    inttostr(trunc(now)- trunc(strtodate('2004-6-4')))
      

  8.   

    同意dulei115() 
    还有,就是第二点的情况可以考虑写为:
    inttostr(DaysBetween(Date,strtodate('2004-6-4')))
    就是说跟Date比较和跟Now比较的结果是不一样的
      

  9.   

    好了,就是dulei115() 说的那样
      

  10.   

    to S.F.(萧寒(Chinasf)): 不用那么麻烦吧,直接打开Delphi的帮助,输入要看的函数名,打开相应的帮助,如果需要引用什么单元,它的“Unit”中会有说明
      

  11.   

    TryStrToDateTime
    或者TryStrToDate
      

  12.   

    var
      dt1: TDateTime;  ShowMessage(BoolToStr(TryStrToDate('2003-02-29', dt1), True));
      

  13.   

    var
      d: Tdatetime;
    begin
      if not TryStrToDateTime('2003-1-35', d) then
        showmessage('输入的日期字符串是不合法的')
      else
        //转换成功,直接使用d
      

  14.   

    function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
    或者
    function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;如果合法的日期时间类型的话,返回值为True,并且将转换成日期时间类型的数据赋值到Value中