Schedule icon
Log icon

Executes flow on schedule trigger with DateTimeBetween condition

Gate a daily Kestra Schedule trigger with the DateTimeBetween condition so a flow runs only inside a fixed start and end date window.

Categories
Core
id: schedule-condition-datetimebetween
namespace: company.team

triggers:
  - id: schedule
    type: io.kestra.plugin.core.trigger.Schedule
    cron: "0 11 * * *"
    when: "{{ trigger.date > '2025-12-31T23:59:59Z' and trigger.date <
      '2025-01-01T00:00:00Z' }}"

tasks:
  - id: hello
    type: io.kestra.plugin.core.log.Log
    message: Demo for DateTimeBetween condition

Run a daily cron schedule in Kestra but execute the flow only while the trigger date falls inside a defined start and end window, using the io.kestra.plugin.core.condition.DateTimeBetween condition. This pattern is ideal for time-boxed campaigns, seasonal jobs, promotional periods, or any pipeline that should fire on a regular cadence but only between two calendar dates, without manually enabling and disabling the schedule.

How it works

  1. A io.kestra.plugin.core.trigger.Schedule trigger fires every day at 11am using the cron expression 0 11 * * *.
  2. The trigger carries a io.kestra.plugin.core.condition.DateTimeBetween condition that compares {{ trigger.date }} against the before and after bounds.
  3. The condition only evaluates to true when the trigger date sits inside the configured window, so the execution is created only on qualifying days.
  4. When the window is satisfied, the hello task (io.kestra.plugin.core.log.Log) runs and logs a confirmation message.

The DateTimeBetween condition also works with either bound alone: provide only before to match any date earlier than that instant, or only after to match any date later than it. Provide both, as in this example, to match dates that fall between the two.

What you get

  • A single declarative schedule that self-activates and self-deactivates around a date range.
  • No off-cadence manual toggling of triggers.
  • Clear execution history showing exactly which days qualified.

Who it's for

  • Data and platform engineers running seasonal or campaign-bound pipelines.
  • Teams that need recurring jobs scoped to a contract, promotion, or fiscal window.

Why orchestrate this with Kestra

Cron alone tells a job when to attempt a run, but it cannot express a calendar window without external glue. Kestra's trigger conditions add that gating declaratively in YAML, alongside retries, event-based triggers, full execution lineage, and observability. The schedule stays in version control, and the window is auditable in one place rather than scattered across scripts or manual enable and disable steps.

Prerequisites

  • A running Kestra instance.

Secrets

  • None. This flow references no secrets.

Quick start

  1. Copy this flow into your Kestra instance.
  2. Adjust the before and after bounds to your target window.
  3. Save and let the schedule run, the flow executes only on qualifying days.

How to extend

  • Replace the hello log task with your real workload.
  • Change the cron expression to a different cadence (hourly, weekly).
  • Combine DateTimeBetween with other conditions such as day-of-week or variable checks.
  • Use a single bound to model open-ended start or end dates.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.