如何在SQL Server中将分钟数转换为间隔?

时间:2015-07-11 06:43:29

标签: sql-server tsql

我的duration表格中有一个time(7)appointments列。

我知道如何使用

获得预约的分钟数
select durationMinutes = DateDiff(n, a.StartOn, a.EndOn) 
from appointments a

但我的duration列是time(7)

如何将int转换为duration

2 个答案:

答案 0 :(得分:1)

您可以尝试使用DATEADD功能并将分钟添加到00:00:00时间。

DATEADD(MINUTE, @durationMinutes, '00:00:00')

答案 1 :(得分:0)

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)';