Try this function
CREATE FUNCTION [dbo].[RoundTime] (@Time datetime, @RoundTo float)
RETURNS datetime
AS
BEGIN
DECLARE @RoundedTime smalldatetime
DECLARE @Multiplier float
SET @Multiplier= 24.0/@RoundTo
SET @RoundedTime= ROUND(CAST(CAST(CONVERT(varchar,@Time,121) AS datetime) AS float) * @Multiplier,0)/@Multiplier
RETURN @RoundedTime
END
select dbo.roundtime('13:15',0.5)
The 1st param is the time to be rounded and the 2nd will be base on your list (0.5-half hour, 1-one hour, ...)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…