Cron Expression: Every Day at 8 AM and 8 PM (0 8,20 * * *)
Need to generate a cron expression?
Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!
Cron Expression: Every Day at 8 AM and 8 PM (0 8,20 * * *)
The cron expression 0 8,20 * * * executes a task every day at 8:00 AM and 8:00 PM (20:00), making it ideal for twice-daily operations, reports, and tasks that should run at the start and end of the business day.
Expression Breakdown
0 8,20 * * *
│ │ │ │ │
│ │ │ │ └─── Day of week: * (every day)
│ │ │ └───── Month: * (every month)
│ │ └─────── Day of month: * (every day)
│ └─────────── Hour: 8,20 (8 AM and 8 PM)
└───────────── Minute: 0 (at minute 0)
Field Values
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | At minute 0 |
| Hour | 8,20 | Hours 8 and 20 (8 AM and 8 PM) |
| Day of Month | * | Every day (1-31) |
| Month | * | Every month (1-12) |
| Day of Week | * | Every day of week (0-7) |
List Syntax
The 8,20 in the hour field is a list that means "hour 8 and hour 20":
- Runs at: 08:00 (8:00 AM) and 20:00 (8:00 PM)
- Total: 2 executions per day
Execution Time
This expression runs 2 times per day at:
- 08:00 (8:00 AM) and 20:00 (8:00 PM)
Common Use Cases
1. Twice-Daily Reports
0 8,20 * * * /usr/bin/python3 /scripts/generate-twice-daily-report.py
Generate reports at the start and end of the business day.
2. Twice-Daily Backups
0 8,20 * * * /usr/local/bin/twice-daily-backup.sh
Create backups at the start and end of each day.
3. Twice-Daily Data Sync
0 8,20 * * * /usr/bin/python3 /scripts/sync-twice-daily-data.py
Sync data from external systems or APIs twice daily.
4. Twice-Daily Cache Refresh
0 8,20 * * * /usr/bin/python3 /scripts/refresh-cache.py
Refresh cached data or computed values twice daily.
Example Implementations
Twice-Daily Report Script
# generate-twice-daily-report.py
import json
from datetime import datetime
import sqlite3
def generate_twice_daily_report():
conn = sqlite3.connect('/var/data/app.db')
cursor = conn.cursor()
current_hour = datetime.now().hour
period = "morning" if current_hour == 8 else "evening"
# Get data based on period
if period == "morning":
# Get yesterday's data
yesterday = datetime.now() - timedelta(days=1)
start_date = yesterday.replace(hour=0, minute=0, second=0)
end_date = yesterday.replace(hour=23, minute=59, second=59)
else:
# Get today's data so far
today = datetime.now()
start_date = today.replace(hour=0, minute=0, second=0)
end_date = today
cursor.execute('''
SELECT
COUNT(*) as total_requests,
AVG(response_time) as avg_response_time,
COUNT(CASE WHEN status_code >= 400 THEN 1 END) as errors
FROM requests
WHERE timestamp >= ? AND timestamp <= ?
''', (start_date, end_date))
metrics = cursor.fetchone()
report = {
'period': period,
'date': datetime.now().strftime('%Y-%m-%d'),
'time': datetime.now().strftime('%H:%M:%S'),
'metrics': {
'total_requests': metrics[0],
'avg_response_time': round(metrics[1], 2) if metrics[1] else 0,
'errors': metrics[2]
}
}
with open(f'/var/reports/{period}_{datetime.now().strftime("%Y%m%d_%H")}.json', 'w') as f:
json.dump(report, f, indent=2)
print(f"{datetime.now()}: {period.capitalize()} report generated")
conn.close()
if __name__ == '__main__':
generate_twice_daily_report()
Best Practices
- Twice-Daily Timing: 8 AM and 8 PM provide good start/end points
- Error Handling: Implement comprehensive error handling and logging
- Locking: Use file locks to prevent concurrent execution
- Monitoring: Set up alerts for failed jobs
- Performance: Optimize tasks to complete efficiently
When to Use
✅ Good for:
- Twice-daily reports
- Twice-daily backups
- Twice-daily data sync
- Start/end of day operations
- Twice-daily cache refresh
❌ Avoid for:
- Real-time critical operations
- Tasks requiring more frequent execution
Related Patterns
| Pattern | Expression | Description |
|---|---|---|
| Twice daily | 0 8,20 * * * | 8 AM and 8 PM |
| Daily at 8 AM | 0 8 * * * | Once daily at 8 AM |
| Daily at 8 PM | 0 20 * * * | Once daily at 8 PM |
Conclusion
The 0 8,20 * * * expression is perfect for twice-daily operations. It's commonly used for reports, backups, and data synchronization that should run at the start and end of each day, providing a good balance between keeping systems updated and managing resource usage.
Need to generate a cron expression?
Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!