Can I schedule a task for a certain day of the month?

To set up your task to run on a specific day of every month – say, the first of the month – have your task subscribe to   mechanic/scheduler/daily, then use logic like this inside your task script:

{% assign day_of_month = "now" | date: "%-d" | times: 1 %}

{% log day_of_month: day_of_month %}

{% if event.preview or day_of_month == 1 %}
  {% action "echo", "It's the first!" %}
{% endif %}

Hint: The times: 1 filter is in place to convert the string, as returned by the date filter (i.e. "1"), to an integer (i.e. 1). By converting it to an integer, our condition can be a simple day_of_month == 1, instead of day_of_month == "1".

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.