问题
I created Lotus Notes database for HR Department. I entered field Join date. Also entered field “Total Service Period”. I want get the calculated Number of Years, Month and Days of service in to “View” and to update the service period daily.
回答1:
This is just a re-posting of a formula I posted seven years ago in the Lotus Notes and Domino 4 and 5 forum:
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.")
回答2:
Didn't test this one fully, but just for the fun I wanted to share this formula:
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)
I assume months and days can be calculated in a similar way.
来源:https://stackoverflow.com/questions/3262169/no-of-years-month-and-days