Last active
September 14, 2020 17:28
-
-
Save JerryNixon/ab533c31ab32a86ae28da5125a51c37b to your computer and use it in GitHub Desktop.
Convert milliseconds to Hours/Minutes/Seconds printable format in TSQL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare @ms bigint = 123456789; | |
| declare @start datetime = '1/1/2000'; | |
| declare @date datetime = dateadd(millisecond, @ms, @start); | |
| declare @day_diff int = datediff(day, @start, @date); | |
| declare @time time = cast(@date as time); | |
| declare @value varchar(max) = concat( | |
| @day_diff, ' Day(s) ', | |
| format(@time, 'hh'), ' Hour(s) ', | |
| format(@time, 'mm'), ' Minute(s) ', | |
| format(@time, 'ss'), ' Seconds(s) ', | |
| format(@time, 'fff'), ' Milliseconds(s) '); | |
| print @value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment