2014年1月24日 星期五

日期相差多少年、月、日、時、分、秒

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  a,b: Tdatetime;
  c: string;
begin
  a:=2007/3/13;
  b:=2006/3/2;
  c := '';
  if (daysbetween(a,b) div 30) <> 0 then
    c := inttostr(daysbetween(a,b) div 30)+'個月';

  if ((daysbetween(a,b) mod 30) <> 0)and ((daysbetween(a,b) div 30) <> 0)then
    c := c + '又' + inttostr(daysbetween(a,b) mod 30)+'天'
  else if (daysbetween(a,b) mod 30) <> 0 then
    c := inttostr(daysbetween(a,b) mod 30)+'天';

  showmessage(c);
  showmessage(inttostr(yearsbetween(a,b))+'年');
  showmessage(inttostr(monthsbetween(a,b))+'月');
  showmessage(inttostr(daysbetween(a,b))+'天');
  showmessage(inttostr(hoursbetween(a,b))+'小時');
  showmessage(inttostr(minutesbetween(a,b))+'分鐘');
  showmessage(inttostr(secondsbetween(a,b))+'秒');  
end;

沒有留言:

張貼留言