Follow

Code Snippet - Looping a Script Using Dates

If you want to loop a script only during a specific month (or other date option) then you could consider this as an option:

var MyYear, MyMonth, MyDay: Integer;

DecodeDate(Now, MyYear, MyMonth, MyDay);

WriteLn(Now);
WriteLn(MyYear);
WriteLn(MyMonth);
WriteLn(MyDay);

if MyMonth = 6 then
  PAL.Loop := True;

 

Firstly we need to declare the variables for the different parts of the date, then we decode the current date (Now) into the different parts, finally we check for a specific month which in this case is June, the 6th month of the year.

The WriteLn commands simply display the various date parts to show you what you can work with.

You could of course include a second (or more) option after checking for the correct month, which would check for a specific day which could be used to run a script from, on or up to specific days.

 

 

This option would loop a script until the end of June:

var MyYear, MyMonth, MyDay: Integer;

DecodeDate(Now, MyYear, MyMonth, MyDay);

WriteLn(Now);
WriteLn(MyYear);
WriteLn(MyMonth);
WriteLn(MyDay);

While MyMonth <= 6 then
  PAL.Loop := True;

 

This snippet would loop a script in June until the 19th (as we have checked for less than the 20th day and not included the 20th day):

var MyYear, MyMonth, MyDay: Integer;

DecodeDate(Now, MyYear, MyMonth, MyDay);

WriteLn(Now);
WriteLn(MyYear);
WriteLn(MyMonth);
WriteLn(MyDay);

If (MyMonth = 6) and (MyDay < 20) then
  PAL.Loop := True;

 

When the if statement is met or as long as the while statement is not valid then the script will stop looping.

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

Comments