2010-07-16 185 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) 

我假设月和日可以用类似的方法计算。