想知道date1和date2兩者究竟相差多少年、月、日、時、分、秒???
所以就寫了一個函式如下:
輸入兩個時間,可以比對相差多少年、月、日、時、分、秒
date1 = 2023/01/04 20:25:00
date2 = 2023/01/11 20:51:00
0 years,0 months,7 days,0 hours,26 minutes,34 seconds.189 milliseconds
function DateDiffK(date1, date2: TDateTime):String;
function DateDiffK(date1, date2: TDateTime):String;
var
c: string;
years, months, days, hours, minutes, seconds, milliseconds:Integer;
begin
Result := '';
c := '';
years := YearsBetween(date1, date2);
IF IncYear(date2, -years) < date1 then
years := years-1;
date2 := IncYear(date2, -years);
months := MonthsBetween(date1, date2);
IF IncMonth(date2, -months) < date1 then
months := months-1;
date2 := IncMonth(date2, -months);
days := DaysBetween(date1, date2);
IF IncDay(date2,-days) < date1 then
days := days-1;
date2 := IncDay(date2,-days);
hours := HoursBetween(date1, date2);
IF IncHour(date2, -hours) < date1 then
hours := hours-1;
date2 := IncHour(date2, -hours);
minutes := MinutesBetween(date1, date2);
IF IncMinute(date2, -minutes) < date1 then
minutes := minutes-1;
date2 := IncMinute(date2, -minutes);
seconds := SecondsBetween(date1, date2);
IF IncSecond(date2, -seconds) < date1 then
seconds := seconds-1;
date2 := IncSecond(date2, -seconds);
milliseconds := MilliSecondsBetween(date1, date2);
c := IntToStr(years)+' years,'+IntToStr(months)+' months,'+IntToStr(days)+' days,'+IntToStr(hours)+' hours,'+IntToStr(minutes)+' minutes,'+ IntToStr(seconds)+' seconds';
if (milliseconds > 0) then
begin
c := c+'.'+IntToStr(milliseconds)+' milliseconds';
end;
Result := c;
end;
我們團隊使用Delphi已經30年以上的經驗,如果有什麼問題,歡迎與我們聯繫,也可以在下方留言處與我們分享,感謝您!!
手刀試用=>蝦皮對帳王
手刀試用=>康捷雲端ERP
相關文章
👉 Delphi-Component-TProgressBar進度條範例
👉 網路版市招明年元旦上路,財部盤點四大適用情境
賦稅署官員表示,如果個人當月銷售額未達營業稅起徵點(銷售貨物8萬元;勞務4萬元)而暫免申請稅籍登記,就不會有網路版市招新制適不適用的問題。
👉 蝦皮對帳王-蝦皮對帳結果一覽表-為什麼要對帳?無對應???
👉 蝦皮對帳王-對帳原理分析-有訂單,有撥款だいじょうぶ(大丈夫);有訂單,沒撥款 歐NO~~~~~!!!
[蝦皮服務] 訂單完成後什麼時候能夠收到款項呢?
任何一套系統的撰寫與維護,都需要相對應的人力與雲端資料庫來維持。
感謝您願意使用我們的系統。
期待您的留言

Comments