Andy Mallon disparages some Microsoft intern’s summer of 1996 project:
SQL Agent’s schema is older than me. It handles dates, times, and durations like it’s 1980 by using integers instead of date/time data types. My buddy Aaron Bertrand talks more about Dating Responsibly so that you can have a good datetime with your own database.
I was writing a query to pull recent job failures from SQL Agent’s
msdb
job history, and knew that I didn’t want to deal with the wonky date/time formats. Specifically, I was queryingmsdb.dbo.sysjobhistory
to find the Start Time, End Time, and Duration of job runs that failed. If you aren’t familiar with that table, you can look at it over in the docs.
Andy does point out the built-in function but then explains why a separate function is superior. Andy also happens to furnish that function, so check it out.