Back to Home

Cron Expression: January 1st at Midnight (0 0 1 1 *)

CronOS Team
cronschedulingyearlynew-yeartutorial

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!

Generate Cron Expression

Cron Expression: January 1st at Midnight (0 0 1 1 *)

The cron expression 0 0 1 1 * executes a task on January 1st at midnight (00:00), making it ideal for yearly operations, new year tasks, and annual maintenance.

Expression Breakdown

bash
0 0 1 1 *
│ │ │ │ │
│ │ │ │ └─── Day of week: * (every day)
│ │ │ └───── Month: 1 (January)
│ │ └─────── Day of month: 1 (first day)
│ └───────── Hour: 0 (at hour 0, midnight)
└─────────── Minute: 0 (at minute 0)

Field Values

FieldValueMeaning
Minute0At minute 0
Hour0At hour 0 (midnight)
Day of Month1First day
Month1January
Day of Week*Every day of week (0-7)

Execution Time

This expression runs once per year at:

  • January 1st at 00:00 (midnight, New Year's Day)

Common Use Cases

1. Yearly Reports

bash
0 0 1 1 * /usr/bin/python3 /scripts/generate-yearly-report.py

Generate annual reports or summaries for the previous year.

2. Yearly Backups

bash
0 0 1 1 * /usr/local/bin/yearly-backup.sh

Create full yearly backups or archives.

3. Yearly Maintenance

bash
0 0 1 1 * /usr/local/bin/yearly-maintenance.sh

Run annual system maintenance, cleanup, or optimization.

4. Data Archiving

bash
0 0 1 1 * /usr/local/bin/archive-yearly-data.sh

Archive yearly data or move it to long-term storage.

5. License Renewal

bash
0 0 1 1 * /usr/bin/python3 /scripts/process-license-renewals.py

Process annual license renewals or subscriptions.

Example Implementations

Yearly Report Script

python
# generate-yearly-report.py
import json
from datetime import datetime
import sqlite3

def generate_yearly_report():
    conn = sqlite3.connect('/var/data/app.db')
    cursor = conn.cursor()
    
    # Get data from previous year
    current_year = datetime.now().year
    previous_year = current_year - 1
    
    cursor.execute('''
        SELECT 
            COUNT(*) as total_transactions,
            SUM(amount) as total_revenue,
            COUNT(DISTINCT user_id) as unique_customers,
            AVG(amount) as avg_transaction_value
        FROM transactions
        WHERE YEAR(created_at) = ?
    ''', (previous_year,))
    
    metrics = cursor.fetchone()
    
    report = {
        'year': previous_year,
        'generated_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
        'metrics': {
            'total_transactions': metrics[0],
            'total_revenue': round(metrics[1], 2) if metrics[1] else 0,
            'unique_customers': metrics[2],
            'avg_transaction_value': round(metrics[3], 2) if metrics[3] else 0
        }
    }
    
    with open(f'/var/reports/yearly_{previous_year}.json', 'w') as f:
        json.dump(report, f, indent=2)
    
    print(f"{datetime.now()}: Yearly report generated for {previous_year}")
    conn.close()

if __name__ == '__main__':
    generate_yearly_report()

Best Practices

  1. New Year Timing: January 1st marks a clean yearly boundary
  2. Error Handling: Implement comprehensive error handling and logging
  3. Locking: Use file locks to prevent concurrent execution
  4. Monitoring: Set up alerts for failed yearly jobs
  5. Resource Management: Yearly jobs may be very heavy, monitor resources

When to Use

Good for:

  • Yearly reports
  • Yearly backups
  • Yearly maintenance
  • Data archiving
  • Annual operations

Avoid for:

  • Tasks requiring more frequent execution
  • Real-time critical operations

Related Patterns

PatternExpressionDescription
January 1st0 0 1 1 *New Year's Day
Quarterly0 0 1 1,4,7,10 *First day of quarter
Every 6 months0 0 1 1,7 *January and July

Conclusion

The 0 0 1 1 * expression is perfect for yearly operations that should run on New Year's Day. It's commonly used for annual reports, backups, and maintenance tasks, providing a clean yearly cycle for recurring operations.

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!

Generate Cron Expression