我正在尝试获取两个 DateTime 值之间的 DateTime 差异。
查询我到目前为止,
DECLARE @start datetime = '2012-01-01 12:00:00.000'
DECLARE @end datetime = '2013-01-01 11:59:59.999'
SELECT
CONVERT(VARCHAR(5),DATEDIFF(YYYY, @start, @end))
+'-'+ CONVERT(VARCHAR(5),DATEDIFF(MONTH, @start, @end))
+'-'+ CONVERT(VARCHAR(5),DATEDIFF(SECOND, @start, @end)/86400)
+' '+ CONVERT(VARCHAR(5),DATEDIFF(SECOND, @start, @end)%86400/3600)
+':'+ CONVERT(VARCHAR(5),DATEDIFF(SECOND, @start, @end)%3600/60)
+':'+ CONVERT(VARCHAR(5),(DATEDIFF(SECOND, @start, @end)%60))
+'.'+ CONVERT(VARCHAR(5),(DATEDIFF(SECOND, @start, @end)%100))
AS [YYYY-MM-DD HH:MM:SS.MSS]
期望的输出
0001-00-00 23:59:59.999
365 Days, 23 Hours, 59 Minutes, 59 Seconds, 999 Milliseconds
实际输出
1-12-366 8784:0:0.0
谢谢