调用DateUnits单元中的DaysBetween函数得出相差多少天,再*每天有多少秒。(DELPHI6)

解决方案 »

  1.   

    可以加点分吗,这么少,答案如下:declare @a datetime
    declare @b datetimeset @a='2002-04-26 23:00'
    set @b='2002-05-01 8:05'select datediff(second,@a,@b)
      

  2.   

    type
      TTimeCompareType=set of (tcSecond,tcMinute,tcHour,tcDay,tcWeek,tcMonth,tcYear);
    function TPublicUnit.TimeBetween(Time1, Time2: TDateTime;CompareType:TTimeCompareType): Longint;
    var
       HourResult, MinuteResult, SecondResult ,MiscSencondResult: word;
       TimeDiff: TDateTime;
       Sign:boolean;
       retval:LongInt;
    begin
       if Time1 < Time2 then begin
          TimeDiff := Time2 - Time1;
          Sign:=false;
       end
       else begin
          TimeDiff := Time1 - Time2;
          Sign:=true;
       end;   DecodeTime(TimeDiff, HourResult, MinuteResult, SecondResult,MiscSencondResult);   if tcSecond in CompareType then begin
          retval := (HourResult * 3600) + (MinuteResult * 60)+ SecondResult;
          end
       else if tcMinute in CompareType then begin
          retval := (HourResult * 60) + MinuteResult;
          end
       else if tcHour in CompareType then begin
          retval := HourResult;
       end
       else begin
          retval:=-1;
          Sign:=true;
       end;   if (not Sign) then
         TimeBetween:=-(retval)
       else
         TimeBetween:=retval;
    end;
      

  3.   

    function SecondsBetween(const ANow, AThen: TDateTime): Int64;DescriptionCall SecondsBetween to obtain the difference, in seconds, between two TDateTime values. SecondsBetween counts only entire seconds that have elapsed. Thus, SecondsBetween reports the difference between 9:00:00 AM and 9:00:00:999 AM as 0 because the difference is one millisecond short of an entire second.
      

  4.   

    我用 的为DELPHI
    不能SQL的
      

  5.   

    哈哈,两个TDATETIME直接减就可以求差了 。Tdatetime就是double啊,
    1秒=1其他按比例算
      

  6.   

    怎么会呢?我实验过啊。看看DELPHI自己怎么说的type TDateTime = type Double;To find the fractional number of days between two dates, simply subtract the two values, 看,就是这样啊,你怎么个不对法?你的时间是怎么取到的?是不是后面有微秒的?那样就有小数了。
      

  7.   

    你这两个呢相减的多少呢
    a=2002-04-26 23:00
    b=2002-05-01 8:05
    b-a
      

  8.   

    var
      a,b:Tdatetime;
      temp:double;
    begin
      a:=strtodatetime('2002-04-26 23:00');
      b:=strtodatetime('2002-05-01 8:05');  temp:=b-a;
      edit1.text:=floattostr(temp);得到。
    4.37847222221899天。
      

  9.   

    改一下
    var
      a,b:Tdatetime;
      temp:integer;
    begin
      a:=strtodatetime('2002-04-26 23:00');
      b:=strtodatetime('2002-05-01 8:05');  temp:=round((b-a)*24*60*60);
      edit1.text:=inttostr(temp);
    end;得到378300(秒)这下大家满足了吧~!
      

  10.   

    通用点。round((strtodatetime('时间1')-strtodatetime('时间2'))*86400);