本文介绍了如何在两列中找到timeDifferece的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How to subtract this: InTime(nvarchar(20)) – OutTime(nvarchar(20))¬¬ in sql server 2005
Values will be in both of columns like 10:00, 10:30, 10:40 etc…
推荐答案
declare @InTime nvarchar(10) set @InTime='10:00'
declare @OutTime nvarchar(10) set @OutTime='11:30'
select datediff(minute,convert(datetime, convert(char(10), @InTime,110)),convert(datetime, convert(char(10),@OutTime, 110)))
DECLARE @A DATETIME
DECLARE @B DATETIME
DECLARE @Secs DECIMAL(18, 2)
SET @A = '2005-08-06 12:08:00.000'
SET @B = '2005-08-18 00:30:19.000'
SELECT @Secs = DATEDIFF(s, @A, @B) / 60.000000 / 60.00000 / 24.000000
select @Secs
select DATEDIFF(day,col1,col2) AS NumberOfDays,
DATEDIFF(hour,col1,col2) AS NumberOfHours,
DATEDIFF(minute,col1,col2) AS NumberOfMinutes FROM Your_Table
select DATEDIFF(day,2012-06-19,2012-06-20) AS NumberOfDays,
DATEDIFF(hour,2012-06-19,2012-06-20) AS NumberOfHours,
DATEDIFF(minute,2012-06-19,2012-06-20) AS NumberOfMinutes FROM Your_Table
问候,
AP
Regards,
AP
这篇关于如何在两列中找到timeDifferece的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!