关于计算日期的问题!白送分的! (100分)

  • 主题发起人 主题发起人 PigDong
  • 开始时间 开始时间
P

PigDong

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何计算两个日期之间的天数?如2002-1-1与2001-8-1之间相隔多少天?直接
相减行吗?
 
function DaysBetween(const ANow, AThen: TDateTime): Integer;
 
function GetDates(D1,D2:TDate):Integer;
begin
Result:=Trunc(D2-D1);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
t1,t2,td:tdatetime;
begin
T1:=StrToDateTime('2002-5-26 20:30:10.100');
T2:=now;
td:=t2-t1;
Label1.Caption:=IntToStr(floor(td));
end;
 
多人接受答案了。
 
procedure TForm1.TimeSetup1;
var
yr,mr,dr: Word;
td1,td2,dd: TdateTime;
begin
td1:=StrtoDate(Edit17.Text);
td2:=StrtoDate(Edit18.Text);
dd:=td2-td1;
decodedate(dd,yr,mr,dr);
if yr-1900<0 then
begin
time2:=dr-29;
end;
if yr-1900>=0 then
begin
if mr=3 then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+1;
end;
if (mr=1) or (mr=4) or (mr=5) then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+2;
end;
if (mr=2) or (mr=6) or (mr=7) then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+3;
end;
if mr=8 then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+4;
end;
if (mr=9) or (mr=10) then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+5;
end;
if (mr=11) or (mr=12) then
begin
time2:=(yr-1900)*365+(mr-1)*30+dr+6;
end;
end;
end;
 
后退
顶部