Schedule Hourly Batch Using Cron Expression - Start on Abritrary Day of Month

My answer here is I'm assuming when you say 'random' you mean, you need the flexibility to allow your users to pick any start date they want to commence the hourly job, which will the run indefinitely.

The Cron expression will either define a specific time to run the job or a reoccuring one, by use of the wild card characters. It does not as far as I can see have the ability to define a start time/date for a reocurrance to start in one expression. So my approach would be to have specific schedule for your random day and then have that commence the hourly schedule.

The following will create a Schedule to run every hour, starting on the next hour from submission.

System.schedule('Hourly', '0 0 * * * ?', new MyHourlySchedule() );

Given this, create a schedule class that can be scheduled on the day you need.

public with sharing class MyScheduleStart implements Schedulable
{
    public void execute(SchedulableContext ctx) 
    {
        System.schedule('Hourly', '0 0 * * * ?', new MyHourlySchedule() );  
    }
}

To schedule a specific date and time for the above.

System.schedule('Start', '0 0 0 10 9 ? 2013' , new MyScheduleStart() );

This will start your hourly schedule on the 10th of September 2013.


From the Developer Console, an Apex Scheduler can be scheduled to run every hour :-

RunReport1 m = new RunReport1();
String sch = '0 55 * * * ?'; 
String jobID = system.schedule('RunReport1', sch, m);

RunReport1 is the Apex Scheduler class that implements Schedulable interface. This will be run 55 minutes past every hour. Sequence format for sch is :-

Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year