Last active
March 30, 2026 14:48
-
-
Save tcartwright/0d63a50f3d279f6b99703981cfe37090 to your computer and use it in GitHub Desktop.
SQL SERVER: Per Row Time diff with days and milliseconds in timespan format
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
| -- expects rows to be in reverse order, if not in reverse order, then need to switch the columns in the datediff | |
| CONCAT( | |
| DATEDIFF(MILLISECOND, LEAD([all_logs].[timestamp]) OVER (ORDER BY [all_logs].[Id] DESC), [all_logs].[timestamp]) / 86400000, '.', | |
| CONVERT(VARCHAR, DATEADD(MILLISECOND, DATEDIFF(MILLISECOND, LEAD([all_logs].[timestamp]) OVER (ORDER BY [all_logs].[Id] DESC), [all_logs].[timestamp]) % 86400000, 0), 114) | |
| ) AS [TimeDiff] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment