|
Have you ever wanted to schedule an adhoc or an on-demand job for an irregular time? For example, would it be possible to automate the process of scheduling an adhoc to run on the first Tuesday after the first Saturday of the month or is this a task that is bound to be done manually?
Using EMUE’s date processing commands, your script can calculate this schedule and as well as other complicated schedules. |
 |
To ensure that the date calculated (for the adhoc to be scheduled) is not one in the past, the desired date will be calculated based on the date that is one month from today. For example, if today is the 15th of the month, then the first Tuesday after the first Saturday of the month has already passed and so the desired date will be in the upcoming month.
To calculate the date that is one month from today, use the DateAdd command. The resulting date will be stored in a variable called NewDate.
DateAdd NewDate &Today 1 “Months”
Next, the scheduling date can be calculated by finding the first day of the month (next month), finding out the day of the week, then adding the appropriate number of days to get to the first Tuesday after the first Saturday of the month.
First determine the first day of next month and store that date in a variable called FirstDayOfMonth. Since we want the first day of next month, we will use NewDate in the FirstDayOfMonth command. That way the resulting date will be the first day of the month that NewDate falls in, which is next month.
FirstDayOfMonth FirstDay NewDate
Then determine what day of the week that day (the first day of the month) falls on. This resulting date will be stored in a variable called DayOfFirstDayOfMonth .
DayOfWeek DayOfFirstDayOfMonth FirstDay
Finally, count forward to get to the first Tuesday after the first Saturday of the month. For example, if the first day of the month is a Thursday, then the DayOfWeek command will return 4, which is the corresponding number. Starting at Thursday (or 4), we would add 5 days to get to Tuesday. And since there is a Saturday that falls between Thursday, the first day of the month, and Tuesday, we know that we have found the first Tuesday after the first Saturday of the month.
If DayOfFirstDayOfMonth eq 0 Then
DateAdd SchDate FirstDay 9 “days”
ElseIf DayOfFirstDayOfMonth eq 1 Then
DateAdd SchDate FirstDay 8 “days”
ElseIf DayOfFirstDayOfMonth eq 2 Then
DateAdd SchDate FirstDay 7 “days”
ElseIf FirstDayOfWeek eq 3 Then
DateAdd SchDate FirstDay 6 “days”
ElseIf DayOfFirstDayOfMonth eq 4 Then
DateAdd SchDate FirstDay 5 “days”
ElseIf DayOfFirstDayOfMonth eq 5 Then
DateAdd SchDate FirstDay 4 “days”
ElseIf DayOfFirstDayOfMonth eq 6 Then
DateAdd SchDate FirstDay 3 “days”
EndIf
The script also includes calculations for scheduling reports to run one night before the last week day of the month.
This script is available for download in the script library.
If you have a script or a process you would like to share, we want to hear from you! Contact us with an idea!