Sasank Sharma
Sasank Sharma

Reputation: 183

How to schedule a task to run on 3rd Sun of the Month

How to schedule a task to run on the 3rd Sun of the Month? Is it possible?

Upvotes: 0

Views: 919

Answers (2)

sprethepa
sprethepa

Reputation: 757

Third Sunday falls between the 15th and 21st of every month.

From the Snowflake documentation, When both a specific day of month and day of week are included in the cron expression, then the task is scheduled on days satisfying either the day of month or day of week. For example, SCHEDULE = 'USING CRON 0 0 10-20 * TUE,THU UTC' schedules a task at 0AM on any 10th to 20th day of the month and also on any Tuesday or Thursday outside of those dates.

https://docs.snowflake.com/en/sql-reference/sql/create-task.html#optional-parameters

Setting the CRON as "0 8 15-21 * SUN" will run the task at 8 am on all days between 15 to 21 and on a Sunday. So scheduling a task to run only on the 3rd Sunday of the month cannot be achieved using CRON alone.

One option is to set the cron to "0 8 15-21 * *" and a stored procedure can be called via a task to check the day(Sunday) and execute the job on Sunday if the result is true else skip the job run.

Upvotes: 1

Vikhyat
Vikhyat

Reputation: 146

Yes, it is possible to schedule a task in snowflake-cloud-platform The command for your requirement could be:

'CREATE OR REPLACE TASK <task_name>
  WAREHOUSE = <your warehouse>
  SCHEDULE = "USING CRON * * 0#3 * SUN UTC"
AS
<your command for expected operation>'

Upvotes: 1

Related Questions