如何在sql server中减去两次?

时间:2023-02-07 16:29:54

So I don't know how to subtract two time(hh:mm:ss) in sql server.

所以我不知道如何在sql server中减去两次(hh:mm:ss)。

This is my statement:

这是我的发言:

where   
 ( CONVERT(TIME(7), [EndWork], 102)) - ( CONVERT(TIME(7), [StartWork], 102)) <
 CONVERT(TIME(7), ' 8:30:00', 102)

4 个解决方案

#1


1  

DECLARE @END_DATE TIME = '' ,    
     @START_DATE  TIME = ''
     SELECT CONVERT(TIME,DATEADD(MS,DATEDIFF(SS, @START_DATE, @END_DATE )*1000,0),114)

#2


3  

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) - 将以分钟为单位返回差异

#3


1  

You can try to use the DATEDIFF function like this:

您可以尝试使用DATEDIFF函数,如下所示:

where DATEDIFF(HH,StartWork, EndWork)

#4


0  

You can simply wrute query like :

您可以简单地判断查询:

SELECT CONVERT(varchar,(EndWork- StartWork), 108) FROM tablename

Output returns (hh:mm:ss) format.

输出返回(hh:mm:ss)格式。

#1


1  

DECLARE @END_DATE TIME = '' ,    
     @START_DATE  TIME = ''
     SELECT CONVERT(TIME,DATEADD(MS,DATEDIFF(SS, @START_DATE, @END_DATE )*1000,0),114)

#2


3  

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) - 将以分钟为单位返回差异

#3


1  

You can try to use the DATEDIFF function like this:

您可以尝试使用DATEDIFF函数,如下所示:

where DATEDIFF(HH,StartWork, EndWork)

#4


0  

You can simply wrute query like :

您可以简单地判断查询:

SELECT CONVERT(varchar,(EndWork- StartWork), 108) FROM tablename

Output returns (hh:mm:ss) format.

输出返回(hh:mm:ss)格式。