Schedule icon
Log icon

Executes flow on schedule trigger with TimeBetween condition

Run Kestra flows only within a defined time window using the TimeBetween condition. Restrict executions to specific hours for time-sensitive automation.

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

triggers:
  - id: schedule
    type: io.kestra.plugin.core.trigger.Schedule
    cron: "@hourly"
    when: "{{ hourOfDay(trigger.date) >= 8 and hourOfDay(trigger.date) < 17 }}"

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

Restrict a recurring schedule so it only fires inside a defined daily time window using the Kestra io.kestra.plugin.core.condition.TimeBetween condition. A plain cron expression runs every time it matches, day or night, but many workloads should only run during business hours, off-peak windows, or maintenance slots. This blueprint shows how to keep an hourly schedule from triggering outside the hours you allow, without juggling multiple cron entries or adding guard logic inside your tasks.

How it works

  • A io.kestra.plugin.core.trigger.Schedule trigger named schedule is configured with the @hourly cron expression, so it evaluates at the top of every hour.
  • The trigger carries a single condition of type io.kestra.plugin.core.condition.TimeBetween.
  • The condition compares {{ trigger.date }} against an after bound of 08:00:00+02:00 and a before bound of 17:00:00+02:00.
  • The execution is created only when the trigger date falls inside that window. Outside 8am to 5pm (+02:00) the hourly tick is skipped.
  • When the condition passes, the hello task (io.kestra.plugin.core.log.Log) runs and logs a demo message confirming the window matched.

The condition also works with a single bound: provide only after to match any time after a moment, or only before to match any time before it.

What you get

  • A schedule that fires hourly but only between 8am and 5pm in the +02:00 timezone.
  • A reusable pattern for gating any trigger by time of day.
  • Clear separation between when a flow may run (the condition) and what it does (the task).

Who it's for

  • Data and platform engineers who need jobs confined to business or off-peak hours.
  • Teams running cost-sensitive workloads that should pause overnight.
  • Anyone replacing brittle multi-line cron schedules with a single readable rule.

Why orchestrate this with Kestra

A raw cron scheduler can express recurrence but cannot easily say only between these hours and skip otherwise without splitting the schedule into awkward ranges. Kestra adds a declarative TimeBetween condition on top of the schedule, so the window lives in plain YAML next to the trigger. You also gain event and schedule triggers, automatic retries, full execution lineage, and version-controlled flows, all of which a standalone cron entry cannot provide.

Prerequisites

  • A running Kestra instance.

Secrets

  • None. This blueprint uses only core tasks and does not reference any {{ secret('NAME') }} values.

Quick start

  1. Add this flow to your Kestra instance.
  2. Adjust the after and before times (and timezone offset) to match your window.
  3. Save and let the @hourly schedule evaluate.
  4. Confirm executions appear only during the allowed hours.

How to extend

  • Swap the hello log task for your real workload (an ingest, a transform, a notification).
  • Change @hourly to a finer or coarser cron expression.
  • Use only after or only before for an open-ended window.
  • Combine TimeBetween with other conditions such as day-of-week filters for tighter control.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.