New to Kestra?
Use blueprints to kickstart your first workflows.
Run Kestra flows only within a defined time window using the TimeBetween condition. Restrict executions to specific hours for time-sensitive automation.
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.
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.io.kestra.plugin.core.condition.TimeBetween.{{ trigger.date }} against an after bound of 08:00:00+02:00 and a before bound of 17:00:00+02:00.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.
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.
{{ secret('NAME') }} values.after and before times (and timezone offset) to match your window.@hourly schedule evaluate.hello log task for your real workload (an ingest, a transform, a notification).@hourly to a finer or coarser cron expression.after or only before for an open-ended window.TimeBetween with other conditions such as day-of-week filters for tighter control.