How SQL calculates NEXT_RUN_DATE for a job schedule?

Francisco picture Francisco · Mar 8, 2010 · Viewed 13.9k times · Source

I have to make a manual calculation of the next run date for a job, can you help me?

Answer

RRUZ picture RRUZ · Mar 8, 2010

to get the next run date for a job you can use then sysschedules and sysjobschedules tables

check the next_run_date and next_runtime columns from the table sysjobschedules

next_run_date int Next date on which the job is scheduled to run. The date is formatted YYYYMMDD.

next_run_time int Time at which the job is scheduled to run. The time is formatted HHMMSS, and uses a 24-hour clock.

see this script

Select sched.*,jobsched.* FROM msdb.dbo.sysschedules AS sched
inner Join msdb.dbo.sysjobschedules AS jobsched ON sched.schedule_id = jobsched.schedule_id

or you can use the msdb.dbo.sp_help_jobschedule stored procedure, to get the same info.

UPDATE

if you need calculate manually the next_run_date you must check the sysschedules table and see the freq_interval, freq_subday_type, freq_subday_interval, freq_relative_interval, freq_recurrence_factor, active_start_date, active_start_time columns to determine the formula.

check this link to see an example of use.