我在我的appointments
表中有duration
类型的time(7)
列。如何在SQL Server中将分钟数转换为时间间隔?
我知道如何使用
select durationMinutes = DateDiff(n, a.StartOn, a.EndOn)
from appointments a
但我duration
列time(7)
获得在预约的分钟数。
如何将int
转换为duration
?
我在我的appointments
表中有duration
类型的time(7)
列。如何在SQL Server中将分钟数转换为时间间隔?
我知道如何使用
select durationMinutes = DateDiff(n, a.StartOn, a.EndOn)
from appointments a
但我duration
列time(7)
获得在预约的分钟数。
如何将int
转换为duration
?
declare @Time as Time(7) = '01:02:03';
select @Time as 'Time(7)', DateDiff(minute, 0, @Time) as 'Minutes';
declare @Minutes as Int = 90;
select @Minutes as 'Minutes', Cast(DateAdd(minute, @Minutes, 0) as Time(7)) as 'Time(7)';
您可以尝试DATEADD功能并将分钟添加到00:00:00时间。
DATEADD(MINUTE, @durationMinutes, '00:00:00')
这似乎是工作。不过令人困惑的是,如果第三个参数中有一个字符串字面值,MSDN会提到返回类型是DateTime。 https://msdn.microsoft.com/en-us/library/ms186819.aspx?f=255&MSPPError=-2147217396 –
我认为你可以很容易地将日期时间转换为时间 – Scoregraphic
在这个答案中声明@Time有什么意义? –
@kirsteng - 只显示双向转换的例子:'TIME(7)'到'INT'和'INT'到'TIME(7)'。 – HABO