Domino Code Fragment

Code Name*
2nd last business day
Date*
07/09/2002
Source (or email address if you prefer)*
Gerry Audette
IP address:.142.109.90.94
Description*
Gets the 2nd last business day of the month - of course, it can be mod'd
Type*
Formula
Categories*
Date/Time Handling
Implementation:
None (plug and play)
Required Client:
5.0
Server:
(none)
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Rem **********************************************************
Allows you to determine 2nd last business day of the month.

Assumptions: If the 2nd last day of the month is on a fri or sat, set Business day back Thurs, if 2nd last day of the month is sun, set business day back to Fri. Did not factor in Leap years, assumed the 28th as the only valid last day of Feb.

In this case, this is the default formula for an editable field (AgentRunDate) on a simple form used only to fire the agent. The last section of code is appended only in the agent code.

The first agent ('Send Monthly Reminder) checks this field Daily to see if it equals today. If it does, it fires off a message.

Then a second agent ('Update Agent Run Date') modifies this field on the 7th day of each month. Resetting the 2nd last business day using the current month.


REM **** default value in editable date/time field on form - I called mine AgentRunDate****

Month:=@Month(@Now);
Today := @Day(@Now);
LastDay:= @If(Month=1|Month=3|Month=5|Month=7|Month=8|Month=10|Month=12; 31;
Month=4|Month=6|Month=9|Month=11; 30;
28);

OneDayBeforeLastDayOfMonth := @Adjust(@Now;0;0; +((LastDay-1)-Today);0;0;0);

DayNumberOfWeek := @Weekday(OneDayBeforeLastDayOfMonth);

DaysToAdjust := @If(DayNumberOfWeek=6;1;DayNumberOfWeek=7;2;DayNumberOfWeek=1;2;0);

NextAgentRunDate := @Adjust(OneDayBeforeLastDayOfMonth;0;0;-DaysToAdjust;0;0;0);

REM **** this code appended to above only in second agent, not in field on form *******
FIELD AgentRunDate := AgentRunDate;
@SetField("AgentRunDate"; NextAgentRunDate);SELECT @All