2010-07-16 215 views
0

我爲HR部門創建了Lotus Notes數據庫。我輸入了字段加入日期。也輸入字段「總服務期」。我希望將計算的服務年數,月份和天數計入「查看」並每天更新服務期限。年數,月份和天數

回答

0

這僅僅是一個a formula I posted七年前在Lotus Notes和Domino 4,5論壇再次發帖:

startDate := Time1; 
endDate := Time2; 
startDay := @Day(startDate); 
endDay := @Day(endDate); 
startMonth := @Month(StartDate); 
endMonth := @Month(endDate); 
startYear := @Year(startDate); 
endYear := @Year(endDate); 
lessAYear := @If(endMonth > startMonth;@False; (endMonth = startMonth) & (endDay >= startDay); @False; @True); 
yearsDiff := @If(lessAYear; endYear - startYear - 1; endYear - startYear); 
@Set("endDate"; @Adjust(endDate;-yearsDiff;0;0;0;0;0)); 
monthAdj := @If(startDay>endDay;-1;0); 
monthsDiff := @If(lessAYear; (endMonth + 12) - startMonth + monthAdj; endMonth - startMonth + monthAdj); 
@Set("endDate";@Adjust(endDate;0;-monthsDiff;0;0;0;0)); 
daysDiff := @Integer((endDate - startDate)/86400); 
@Prompt([Ok];"";@Text(yearsDiff) + "years, " + @Text(monthsDiff) + " months, and " + @Text(daysDiff) + " days.") 
0

沒有測試這一個完全,只是爲了好玩我想分享這個公式:

diff:= @Adjust(endDate; [email protected](startDate); [email protected](startDate)+1; 
       [email protected](startDate)+1; 0; 0; 0); 
y:= @Year(diff); 
y:= @If(@IsError(n); 0; n>100; 0; n) 

我假設月和日可以用類似的方法計算。