2

I setup task with following schedule to run every 2nd Monday of the month but seems like it setup task to run every Monday. How can I setup cron schedule to run every 2nd Monday of the month?

USING CRON 0 11 1 * 1-1 UTC

SqlDBA
  • 171
  • 2
  • 12

1 Answers1

0

You're right — standard cron expressions do not natively support "nth weekday of the month" (like "2nd Monday"). If you used a cron like

USING CRON 0 9 * * MON

**it would run every Monday at 9:00 AM, not just the 2nd Monday.

Workaround: Use a Conditional Task Body

**Since Snowflake Tasks don’t support complex cron logic directly, you can: a) Schedule the task to run every Monday b) Add logic inside the task body to check if it's the 2nd Monday

Example: SQL Logic to Check for 2nd Monday

-- Inside your task SQL body
DECLARE today DATE DEFAULT CURRENT_DATE;
DECLARE first_monday DATE;
DECLARE second_monday DATE;

BEGIN   LET first_monday = DATEADD(DAY, (8 - DAYOFWEEK(DATE_TRUNC('MONTH', today))) % 7, DATE_TRUNC('MONTH', today));   LET second_monday = DATEADD(DAY, 7, first_monday);

IF today = second_monday THEN     -- Your actual task logic here     CALL your_procedure();   END IF; END;

Alternative: Use External Scheduler **If you need more flexibility, consider using: a) Apache Airflow b) dbt Cloud c) Azure Data Factory d) AWS EventBridge These support more advanced scheduling patterns.