Are you looking for a cron expression for weekends only? Whether you need to run a backup, send a report, or perform maintenance exclusively on Saturdays and Sundays, this guide will teach you everything you need to know. We'll cover the syntax, provide ready-to-use examples for various platforms, and show you how to avoid common pitfalls. By the end, you'll be able to craft the perfect weekend cron schedule with confidence. And if you ever need a quick solution, don't forget to use our Cron Expression Generator.

What is a Cron Expression?

A cron expression is a string that defines a schedule for automated tasks, known as cron jobs. It's used in Unix-like operating systems and many modern applications and cloud services. The expression consists of five or six fields that specify when a command should run: minute, hour, day of month, month, day of week, and optionally year. For example, 0 0 * * * means every day at midnight. Understanding these fields is essential to creating a cron expression for weekends only.

Understanding the Cron Syntax: Minutes, Hours, Days, and More

The standard cron syntax has five fields:

  • Minute (0-59)
  • Hour (0-23)
  • Day of Month (1-31)
  • Month (1-12)
  • Day of Week (0-7, where both 0 and 7 represent Sunday)

Some systems (like Quartz) add a sixth field for the year. You can use numbers, ranges, lists, steps, and wildcards. For example, * means any value, */5 means every 5 units, and 1,15 means 1 and 15. To target weekends, you'll focus on the day-of-week field.

The Basic Weekend Cron Expression: 0 0 * * 6,0

The most common cron expression for weekends only is 0 0 * * 6,0. This runs at midnight (00:00) every Saturday (6) and Sunday (0). Let's break it down:

  • 0 – minute (0)
  • 0 – hour (0, midnight)
  • * – any day of month
  • * – any month
  • 6,0 – Saturday and Sunday

This expression is widely supported in Unix cron, but be aware that some systems number days differently (e.g., 1=Monday, 7=Sunday). Always check your platform's documentation.

Alternative Syntax: Using SUN and SAT Names

Many cron implementations allow you to use three-letter day names instead of numbers. For example, 0 0 * * SAT,SUN is equivalent to 0 0 * * 6,0. This can make your expression more readable. However, not all systems support names, so test before relying on them.

How to Specify Time: Running at Midnight, Morning, or Evening

You can adjust the time by changing the minute and hour fields. For instance:

  • Midnight: 0 0 * * 6,0
  • Morning (e.g., 6:30 AM): 30 6 * * 6,0
  • Evening (e.g., 9:15 PM): 15 21 * * 6,0

Remember that cron uses the system's local time zone unless specified otherwise. In cloud services, you may need to set the time zone explicitly.

Cron Expressions for Weekends Only in Unix/Linux

In Unix/Linux, you edit the crontab with crontab -e and add a line like:

0 0 * * 6,0 /path/to/your/script.sh

This will run the script every Saturday and Sunday at midnight. To verify your schedule, you can use crontab -l to list your cron jobs. For more complex schedules, consider using our Cron Expression Generator to avoid syntax errors.

Cron Expressions for Weekends Only in Java Quartz Scheduler

Quartz uses a six-field format: second minute hour day-of-month month day-of-week. For weekends only, you can use:

0 0 0 ? * SAT,SUN

Note the ? for day-of-month, which means no specific value. In Quartz, day-of-week names are case-insensitive. This expression triggers at midnight on Saturdays and Sundays.

Cron Expressions for Weekends Only in Spring Boot

Spring Boot uses the Quartz cron format for @Scheduled annotations. To run a method on weekends, use:

@Scheduled(cron = "0 0 0 ? * SAT,SUN")
public void runOnWeekends() {
    // your code
}

Make sure to enable scheduling with @EnableScheduling. This is a clean way to automate weekend tasks in Java applications.

Cron Expressions for Weekends Only in AWS (CloudWatch, EventBridge)

AWS EventBridge (formerly CloudWatch Events) uses a cron expression with six fields: minute hour day-of-month month day-of-week year. For weekends, you can use:

0 0 ? * SAT,SUN *

Note the ? for day-of-month and the trailing * for year. You can also specify a time zone in the event rule. This is useful for triggering Lambda functions or other AWS resources on weekends.

Cron Expressions for Weekends Only in Kubernetes CronJob

Kubernetes CronJob uses standard cron syntax. In your YAML manifest, set the schedule field:

schedule: "0 0 * * 6,0"

This will create a job every Saturday and Sunday at midnight. Remember that the time zone is UTC by default, so adjust accordingly if your tasks need to run in a specific local time.

Cron Expressions for Weekends Only in GitHub Actions

GitHub Actions uses POSIX cron syntax. In your workflow file, you can use:

on:
  schedule:
    - cron: '0 0 * * 6,0'

This triggers the workflow on Saturdays and Sundays at midnight UTC. GitHub Actions also supports time zones via the TZ environment variable if needed.

Cron Expressions for Weekends Only in Python and Node.js

In Python, you can use the croniter library to parse and generate cron expressions. For example:

from croniter import croniter
from datetime import datetime

base = datetime.now()
cron = croniter('0 0 * * 6,0', base)
next_run = cron.get_next(datetime)
print(next_run)

In Node.js, the node-cron package allows you to schedule tasks:

const cron = require('node-cron');

cron.schedule('0 0 * * 6,0', () => {
  console.log('Running on weekends');
});

Both libraries support the standard five-field format.

Common Mistakes and How to Avoid Them

  • Using the wrong day numbering: Some systems start the week on Sunday (0), others on Monday (1). Always verify.
  • Confusing day-of-month and day-of-week: When both are restricted, cron uses OR logic. To avoid issues, use ? in systems that support it.
  • Forgetting time zone: If your server is in UTC, your local weekend might be different. Set the time zone explicitly.
  • Not testing: Always test your expression before deploying. Use online tools or your system's dry-run options.

Testing and Validating Your Cron Expression

To ensure your cron expression works as expected, you can use online validators like crontab.guru or our own Cron Expression Generator. These tools show you the next run times, helping you verify that your schedule is correct. Additionally, you can simulate the next few runs in your code to confirm.

Conclusion: Simplify Your Scheduling with Our Cron Expression Generator

Creating a cron expression for weekends only is straightforward once you understand the syntax. Whether you're using Unix, Java, AWS, or any other platform, the key is to specify the day-of-week field correctly. To save time and avoid errors, use our Cron Expression Generator – it's free and easy to use. You can also explore other tools like our Date Calculator for date-related calculations, or our Free Keyword Planner for SEO insights. For developers, our Hash Generator and JSON Formatter are handy utilities. Start scheduling your weekend tasks today!

Frequently Asked Questions

What is the cron expression for weekends only?

The most common is 0 0 * * 6,0 (or 0 0 * * SAT,SUN), which runs at midnight every Saturday and Sunday.

How do I run a cron job only on Saturdays and Sundays?

Use the day-of-week field with values for Saturday and Sunday. For example, 0 0 * * 6,0.

What does '0 0 * * 6,0' mean in cron?

It means at 00:00 (midnight) on any day of the month and any month, but only when the day of the week is Saturday (6) or Sunday (0).

Can I use names like SUN and SAT in cron expressions?

Yes, many systems allow three-letter abbreviations. For example, 0 0 * * SAT,SUN.

How do I set a cron job to run at a specific time on weekends?

Change the minute and hour fields. For instance, 30 8 * * 6,0 runs at 8:30 AM on weekends.

What is the difference between Unix cron and Quartz cron for weekends?

Unix cron uses five fields, while Quartz uses six (including seconds). Quartz also uses ? for no specific value and supports names.

How do I schedule a cron job for weekends in AWS?

In EventBridge, use a cron expression like 0 0 ? * SAT,SUN * and set the time zone.

How do I schedule a cron job for weekends in Kubernetes?

In the CronJob manifest, set schedule: "0 0 * * 6,0".

How do I test a cron expression for weekends only?

Use online validators like crontab.guru or our Cron Expression Generator to see the next run times.

What are common mistakes when writing weekend cron expressions?

Using the wrong day numbering, mixing day-of-month and day-of-week, forgetting time zones, and not testing.