How We Calculate Time on Task, the Business Hours Between Two Dates
Measuring the number of business hours between two dates using SQL is one of those classic problems that sounds simple yet has plagued analysts since time immemorial.
This comes up in a couple places at dbt Labs:
- Calculating the time it takes for a support ticket to be solved
- Measuring team performance against response time SLAs
We internally refer to this at "Time on Task," and it can be a critical data point for customer or client facing teams. Thankfully our tools for calculating Time on Task have improved just a little bit since 2006.
Even still, you've got to do some pretty gnarly SQL or dbt gymnastics to get this right, including:
- Figuring out how to exclude nights and weekends from your SQL calculations
- Accounting for holidays using a custom holiday calendar
- Accommodating for changes in business hour schedules
This piece will provide an overview of how and critically why to calculate Time on Task and how we use it here at dbt Labs.