Generador de Expresiones Cron

Genera y explica expresiones cron con descripciones legibles para humanos

What is a Cron Expression Generator?

A cron expression generator translates human-readable scheduling requirements into valid cron syntax. Unlike a cron parser — which interprets an existing expression and explains when it will fire — a generator works in the opposite direction: you describe when you want a job to run (every weekday at 9 AM, every 15 minutes during business hours, the first Monday of each month) and the tool produces the correct five-field or six-field expression. This removes the need to memorize positional field order, allowed ranges, and special characters like */, L, or # that vary across platforms.

Cron expressions originated in Unix System V (1983) and follow the POSIX specification for the crontab utility. The classic format uses five fields — minute, hour, day-of-month, month, day-of-week — but modern platforms extend this with a seconds field (Spring, Quartz) or restrict it to remove minute-level granularity (AWS EventBridge rate expressions). A visual builder lets you generate syntactically correct expressions for any target platform without consulting documentation for each one.

Building Cron Expressions Visually

Visual cron builders eliminate the most common source of scheduling bugs: field-order confusion. In POSIX cron, the fields are ordered minute–hour–day–month–weekday, but developers frequently swap day-of-month and day-of-week or confuse 0-indexed vs 1-indexed weekday numbering. A visual interface removes this ambiguity by presenting labeled dropdowns, sliders, or toggle grids for each scheduling dimension.

Effective cron generators provide immediate feedback: as you adjust the schedule, the tool displays the next 5–10 execution times so you can verify the expression matches your intent before deploying it. This preview step catches subtle mistakes like generating 0 9 * * 1-5 (Monday through Friday) when you intended 0 9 * * 0-4 (Sunday through Thursday in 0-indexed systems).

The visual approach is especially valuable for complex schedules that combine multiple constraints: "every 30 minutes between 8 AM and 6 PM, Monday through Friday, except holidays" requires chaining step values (*/30), ranges (8-17), and weekday lists (1-5) — all of which a builder can compose without syntax errors.

From Schedule Requirements to Cron Syntax

Translating a natural-language schedule into cron syntax involves decomposing the requirement into its constituent time dimensions. The process follows a consistent pattern:

  1. Identify the frequency: Is this per-minute, hourly, daily, weekly, or monthly?
  2. Set the interval: Every N units uses the step syntax */N in the relevant field.
  3. Add constraints: Time windows use ranges (9-17), specific days use lists (1,3,5).
  4. Handle edge cases: "Last day of month" uses L (non-POSIX), "second Tuesday" uses # in Quartz.

For example, "run at 2:30 AM on the 1st and 15th of every month" becomes 30 2 1,15 * *. A generator automates this decomposition, ensuring that field values stay within valid ranges (0–59 for minutes, 0–23 for hours, 1–31 for day-of-month, 1–12 for month, 0–7 for day-of-week where both 0 and 7 represent Sunday).

Common pitfalls the generator prevents include using day-of-month 31 for months that have only 30 days, specifying both day-of-month and day-of-week without understanding their OR semantics in standard cron, and forgetting that the hour field uses 24-hour format (no AM/PM).

Platform Compatibility and Format Differences

Not all cron implementations accept the same syntax. A well-designed generator accounts for target platform differences:

  • Standard POSIX cron: Five fields, no seconds. */5 * * * * runs every 5 minutes. Supported by Linux crontab, macOS launchd (via crontab compatibility).
  • Kubernetes CronJob: Five-field POSIX format. Does not support non-standard extensions like L or W. Minimum granularity is one minute.
  • GitHub Actions: Five-field POSIX format in schedule.cron triggers. Runs in UTC only. Minimum interval of 5 minutes enforced by GitHub.
  • AWS EventBridge: Six fields (adds year) with cron(0 9 ? * MON-FRI *) syntax. Uses ? for "no specific value" in day fields. Supports L and W modifiers.
  • Spring/Quartz: Six or seven fields (seconds + optional year). Supports # for "nth weekday of month" and L for "last".

When generating expressions, always specify your target platform. An expression valid for Quartz (e.g., 0 0 9 ? * MON#2 for "second Monday at 9 AM") will fail in a Kubernetes CronJob that only supports standard five-field syntax. The generator validates output against platform-specific rules before presenting the result.

Testing and Validating Generated Expressions

After generating a cron expression, always verify it by checking the next scheduled execution times. A generator should compute at least the next 5 run times relative to the current timestamp. This verification step catches logical errors that are syntactically valid but semantically wrong — for instance, 0 0 30 2 * is valid syntax but will never fire because February never has 30 days.

For production deployments, consider these validation practices:

  • Verify the expression in the same timezone your scheduler uses (UTC for GitHub Actions, configurable for Kubernetes).
  • Check for unintentional "fire every second" expressions that could overwhelm your system — the generator should warn if frequency exceeds a configurable threshold.
  • Test across daylight saving time boundaries to ensure jobs don't skip or double-fire during clock changes.
  • For critical jobs, implement a monitoring alert that fires if the job hasn't run within 2× its expected interval.

The generator's preview function serves as a dry-run: if the next execution times don't match your expectations, adjust the schedule parameters before committing the expression to your CI/CD pipeline, Kubernetes manifest, or infrastructure-as-code template.

Code Examples

Cron expressions for common scheduling patterns

# Kubernetes CronJob — run backup every day at 3:00 AM UTC
apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-backup
spec:
  schedule: "0 3 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: backup-tool:latest
            command: ["./run-backup.sh"]
          restartPolicy: OnFailure

---
# GitHub Actions — deploy every Monday at 9:00 AM UTC
on:
  schedule:
    - cron: '0 9 * * 1'

---
# AWS EventBridge — process reports on weekdays at 6 PM
# Note: EventBridge uses 6-field format with ? for unspecified day
# cron(minutes hours day-of-month month day-of-week year)
Resources:
  WeekdayReportRule:
    Type: AWS::Events::Rule
    Properties:
      ScheduleExpression: "cron(0 18 ? * MON-FRI *)"

Programmatic cron generation in Node.js

// Generate a cron expression from schedule parameters
function generateCron({ minute, hour, dayOfMonth, month, dayOfWeek }) {
  const fields = [
    minute ?? '*',
    hour ?? '*',
    dayOfMonth ?? '*',
    month ?? '*',
    dayOfWeek ?? '*'
  ];
  return fields.join(' ');
}

// Every weekday at 9:30 AM
const workdayMorning = generateCron({
  minute: 30, hour: 9, dayOfWeek: '1-5'
});
// → "30 9 * * 1-5"

// Every 15 minutes during business hours
const businessHours = generateCron({
  minute: '*/15', hour: '9-17', dayOfWeek: '1-5'
});
// → "*/15 9-17 * * 1-5"

// First day of each quarter at midnight
const quarterly = generateCron({
  minute: 0, hour: 0, dayOfMonth: 1, month: '1,4,7,10'
});
// → "0 0 1 1,4,7,10 *"

Standards & Specifications

Preguntas Frecuentes

How does the cron generator build expressions?

The cron generator provides a visual interface where you select schedule parameters — minute, hour, day of month, month, and day of week — and it assembles a valid cron expression. For example, selecting 'every weekday at 9:00 AM' produces '0 9 * * 1-5'. This eliminates the need to memorize field ordering or special characters.

How do I create a cron expression for business hours?

To run a task every hour during business hours (9 AM to 5 PM) on weekdays, use: '0 9-17 * * 1-5'. The '0' means at the start of each hour, '9-17' is the hour range, and '1-5' represents Monday through Friday.

Can I run a task multiple times per hour?

Yes! Use the comma separator or step values. For example, '0,30 * * * *' runs at the top and bottom of every hour (twice per hour), while '*/15 * * * *' runs every 15 minutes (four times per hour).

What's the difference between day of month and day of week?

Day of month (field 3) specifies dates like '1st' or '15th'. Day of week (field 5) specifies days like 'Monday' or 'Friday'. If both are specified (not *), the cron job runs when EITHER condition is met (OR logic).

Is my data sent to a server?

No, all cron generation happens in your browser. Your expressions never leave your device. This ensures complete privacy and security.