SQL 如何在sql server中减去两次?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36906896/
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
how to subtract two time in sql server?
提问by Mohammad Saadeh
So I don't know how to subtract two time(hh:mm:ss)
in sql server.
所以我不知道如何time(hh:mm:ss)
在sql server中减去两个。
This is my statement:
这是我的声明:
where
( CONVERT(TIME(7), [EndWork], 102)) - ( CONVERT(TIME(7), [StartWork], 102)) <
CONVERT(TIME(7), ' 8:30:00', 102)
采纳答案by Chanukya
DECLARE @END_DATE TIME = '' ,
@START_DATE TIME = ''
SELECT CONVERT(TIME,DATEADD(MS,DATEDIFF(SS, @START_DATE, @END_DATE )*1000,0),114)
回答by Abdul Rasheed
Using the DATEDIFF function you will get the difference of two dates/time in Year/Month/Day/Hour/Min/Sec as you required.
使用DATEDIFF函数,您将根据需要获得年/月/日/小时/分钟/秒中两个日期/时间的差异。
Eg:- DATEDIFF ( MINUTE , startdate , enddate )
--will return the diff in minutes
例如:- --DATEDIFF ( MINUTE , startdate , enddate )
将在几分钟内返回差异