DATEDIFF(MINUTE,开始时间,结束时间)
select DATEDIFF(MINUTE,'2022-03-17 09:00',getdate())%60
例句
with a as (
SELECT '2022-03-17 09:00' [Time_]
union
SELECT '2022-03-17 09:10' [Time_]
union
SELECT '2022-03-17 09:20' [Time_]
union
SELECT '2022-03-17 09:30' [Time_]
union
SELECT '2022-03-17 09:40' [Time_]
)
SELECT (CASE WHEN DATEDIFF(MINUTE,Time_,getdate())%60 >=30 THEN (DATEDIFF(MINUTE,Time_,getdate())/60)+0.5 ELSE DATEDIFF(MINUTE,Time_,getdate())/60 END) FROM A