How can I caliculate Number of times my job runs between any selected dattime

  • Hi I have a job which is runs every 6 hours a day.

    2:00 AM, 8:00 AM, 2:00 PM, and 8:00 PM.

    For any give Datetime, I would like to calculate the the # of times my job ran. Please help me get the number.

    Declare @date1 datetime = '2012-12-04 10:20:17.327'

    Declare @date2 datetime = '2012-12-13 10:20:17.327'

  • Query sysjobhistory providing that it stores enough rows and doesnt purge, or tell your job to log the run time to an audit table then query that.

  • Thanks but. Me selecting from sysjobhistory will not work in my case.

    I just want to know if I give 2 dates, how many times does 2:00 , 8:00, 14:00 and 20:00 comes between the below datetimes.

    Declare @date1 datetime = '2012-12-04 10:20:17.327'

    Declare @date2 datetime = '2012-12-13 10:20:17.327'

  • DateDiff in hours then divide by 6 to get the result.

    select datediff(hh,@date1,@date2) / 6 = 36

    Was assuming that the "ran" ment in the past, which is where the sysjobhistory came in to place, instead of how many times should it run between the two dates.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply