I just encountered a problem where I needed a job to run if the the same job ran ran over an hour ago. I stored the last run time in a cookie, poll it, and compare the last run time using SQL’s datediff() function. I check the number of hours since the job last ran thus:
datediff( hh, getdate(), last_run_time )
Then I wondered:”Does datediff() return 0 if the two datetime parameters have the same hour, but different dates? What if I get the hours diff between ‘06/11/2009 10:27:38′ and ‘06/17/2009 10:27:38′?” Whould would I see? Would I see 0? Or would I see the number of days * 24 + the actual hours different in the day?
It turns out the datediff() returns 168. This is good news.