Run Weekend Midnight Maintenance Tasks | CronBase

cron expression Standard
$ 0 0 * * 6,0

Every Saturday and Sunday at midnight.

This cron expression schedules a task to run at exactly midnight (00:00) every Saturday and Sunday. It is commonly used by system administrators and DevOps engineers to perform weekly maintenance, database optimization, and system backups during low-traffic weekend windows to avoid impacting production users.

Minute
0
Hour
0
Day of Month
*
Month
*
Day of Week
6,0

Next 5 Runs

  • in 13h 59m
  • in 1d 13h
  • in 7d 13h
  • in 8d 13h
  • in 14d 13h

* Tools

Code & Implementations

nodejs
const cron = require('node-cron');
const { exec } = require('child_process');

// Schedule task for midnight on Saturday (6) and Sunday (0)
cron.schedule('0 0 * * 6,0', () => {
    console.log(`[${new Date().toISOString()}] Initiating weekend database cleanup...`);
    exec('npm run db:cleanup', (error, stdout, stderr) => {
        if (error) {
            console.error(`[ERROR] Cleanup failed: ${error.message}`);
            return;
        }
        if (stderr) {
            console.warn(`[WARN] Cleanup stderr: ${stderr}`);
        }
        console.log(`[SUCCESS] Cleanup output: ${stdout}`);
    });
}, {
    scheduled: true,
    timezone: "UTC"
});
Setup notes

Install node-cron using 'npm install node-cron' and run this script as a background service using PM2 or Docker.

Partner BetterStack

Monitor this schedule in production

Get alerted the moment this cron job fails, is late, or doesn't run. BetterStack tracks execution, duration, and output — no infrastructure required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 0 ? * 6,0 *)

Systemd Timer

OnCalendarSat,Sun *-*-* 00:00:00

my-task.timer
[Unit]
Description=Timer for cron expression: 0 0 * * 6,0

[Timer]
OnCalendar=Sat,Sun *-*-* 00:00:00
Persistent=true

[Install]
WantedBy=timers.target

Frequently Asked Questions

Does standard cron treat 0 and 7 both as Sunday?

Yes, in most standard cron implementations (such as Vixie cron, commonly found in Linux), both 0 and 7 represent Sunday. However, to guarantee maximum portability across different systems and cloud platforms, using 0 is widely preferred.

What happens if Saturday's run takes longer than 24 hours to complete?

If Saturday's run exceeds 24 hours, Sunday's run will trigger while the previous execution is still active. To prevent race conditions and system overload, you should implement lock files, use `flock` in Bash, or set `concurrencyPolicy: Forbid` in Kubernetes.

How do daylight saving time (DST) transitions affect this midnight schedule?

If your system timezone is configured to a local timezone that observes DST, your job might run twice or be skipped entirely when clocks shift. To avoid this unpredictable behavior, it is highly recommended to configure your system or application schedulers to run strictly in UTC.

Can I target only Saturday instead of both weekend days?

Yes, if you want to run the job exclusively on Saturday, you can modify the day-of-week field to only include 6. The resulting cron expression would be `0 0 * * 6`.

Why is this schedule preferred over daily midnight maintenance?

Running tasks on weekends minimizes the risk of impacting active users, as standard business application traffic is typically at its lowest. This provides a safer window for executing heavy locking operations, schema migrations, or massive data aggregations that could degrade system performance during weekdays.

* Explore

Related expressions you might need

Was this helpful?

Last verified: