SQL Agent Job Schedules with an End Time and Frequency

Nick Ryan 261 Reputation points
2023-06-27T04:24:51.13+00:00

I have found contradictory answers about whether the end time is inclusive or exclusive. My scenario is as follows. My job is scheduled to run every 30 minutes between 4 a.m. and 10 a.m. It runs for the last time at 9:30 a.m. so it would appear it is exclusive. If that's the case, how come I can find several references (including ChatGPT) that claim it is inclusive?

I got to wondering, is it because there's a small delay while it is triggered so by the time it goes to kick off the job, it's already a second or 2 past 10 a.m? Therefore, to make sure it runs at 10 a.m., I'd only need to put my End Time at 10:01 a.m. Or even 10:29:59 a.m. to make absolutely certain.

A definitive answer to how to ensure that last run at 10 a.m. and why there appears to be so much uncertainty as to the inclusive/exclusive matter will be gratefully received.

SQL Server | Other
{count} votes

Accepted answer
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2023-06-27T22:02:06.8333333+00:00

    Yeah, ChatGPT is what they call a "trustworthy source". Not.

    I'm inclined to say that it is exclusive. My first thought was like yours: it depends on when the condition is evaluated. But then it occurred to me that msdb.dbo.sysjobschedules has the columns next_run_date and next_run_time. I set up a job to run every minute with 23:59:00 as the end time. At 23:58 I checked that the job had executed at that time, and then I check the table. The was not there. So already at the execution at 23:58, Agent decided not to run it at 23:59.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. LiHongMSFT-4306 31,571 Reputation points
    2023-06-28T07:10:55.2766667+00:00

    Hi @Nick Ryan

    Agree with Erland, it seems that the end time is not included.

    I test a job start from 2:35 pm to 2:40 pm running every one minute. When I check it in Job Activity Monitor at 2:39 pm, it was not scheduled in the next run column.

    User's image

    A definitive answer to how to ensure that last run at 10 a.m. And why there appears to be so much uncertainty as to the inclusive/exclusive matter will be gratefully received.

    Regarding the uncertainty issue, you may post it in the feedback site: SQL community.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.