我为HR部门创建了Lotus Notes数据库。我输入了字段加入日期。还输入了“总服务期”字段。我希望将计算出的年数,月数和服务天数计入“查看”并每天更新服务期。
答案 0 :(得分:0)
这只是在Lotus Notes和Domino 4 and 5论坛中重新发布a formula I posted 七年前
: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.")
答案 1 :(得分:0)
没有完全测试这个,但只是为了我想分享这个公式的乐趣:
diff:= @Adjust(endDate; -@Year(startDate); -@Month(startDate)+1;
-@Day(startDate)+1; 0; 0; 0);
y:= @Year(diff);
y:= @If(@IsError(n); 0; n>100; 0; n)
我假设可以用类似的方式计算月数和日数。