SQL SQL将时间转换为毫秒
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32602187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:03:26 来源:igfitidea点击:
SQL convert time to milliseconds
提问by Lingo
I have this time-duration: 00:00:23.323
I want to convert it in sql to milliseconds.
我有这个持续时间:00:00:23.323
我想将它在 sql 中转换为毫秒。
EDIT:// I tried this but it isn't very nice:
编辑://我试过这个,但不是很好:
SELECT (DATEPART(hh,'12:13:14.123') * 60 * 60 * 1000)
SELECT (DATEPART(n,'12:13:14.123') * 60 * 1000)
SELECT (DATEPART(s,'12:13:14.123') * 1000)
SELECT DATEPART(ms,'12:13:14.123')
How does it work?
它是如何工作的?
Thanks for your answers.
感谢您的回答。
回答by t-clausen.dk
回答by Lingo
I got it, it isn't the nice way but it works:
我明白了,这不是一个好方法,但它有效:
SELECT (DATEPART(hh,'00:00:23.323') * 60 * 60 * 1000) + (DATEPART(n,'00:00:23.323') * 60 * 1000) + (DATEPART(s,'00:00:23.323') * 1000) + DATEPART(ms,'00:00:23.323') AS 'DurationInMillis'
回答by Mukesh Kalgude
You can use datepart function. like this
您可以使用 datepart 函数。像这样
select DATEPART(MILLISECOND,GETDATE())+DATEPART(second,getdate())*1000