Get Time Duration in [DD hh:mm:ss] format

Spread the love

As DBA, there are various scenarios where I display duration in results. More often, for visual effects, I like to convert the same duration into [DD hh:mm:ss] format.

For example, for representing the duration of total waits, resource waits & signal waits for wait types from [sys].[dm_os_wait_stats].[wait_time_ms] on Grafana dashboard by converting to [DD hh:mm:ss] format:-

Also, for displaying duration of query execution by converting [sys].[dm_exec_request].[start_time] into [DD hh:mm:ss] format :-

For this purpose, I wrote below TSQL function [time2duration] that provides me duration in [DD hh:mm:ss] format:-

Below are 2 sample usage for above function:-

I hope this will be useful to you 🙂


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.