以秒,毫秒显示 [英] Show datediff as seconds, milliseconds
本文介绍了以秒,毫秒显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图计算两个日期时间值之间的差异。
I'm trying to calculate the difference between two datetime values.
我试过 datediff(s,begin,end)
和 datediff(ms,begin,end)
然而,我希望差异返回为秒,毫秒
如下:
I tried datediff(s, begin,end)
and datediff(ms, begin,end)
however I want the difference to be returned as seconds,milliseconds
like the following:
4,14
63,54
推荐答案
SELECT
DATEDIFF(MILLISECOND, begin, end) / 1000,
DATEDIFF(MILLISECOND, begin, end) % 1000
FROM ...;
如果您绝对必须在SQL查询中将其形成为字符串(您的演示层不能做那么?),然后:
If you absolutely must form it as a string in your SQL query (can't your presentation tier do that?), then:
SELECT
CONVERT(VARCHAR(12), DATEDIFF(MILLISECOND, begin, end) / 1000)
+ ','
+ RIGHT('000' + CONVERT(VARCHAR(4), DATEDIFF(MILLISECOND, begin, end) % 1000), 3)
FROM ...;
此外,我真的希望你的列名比 begin $ c更好$ c>和
end
。
Also I really hope you have better column names than begin
and end
.
这篇关于以秒,毫秒显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文