I need a function that rounds UP to the nearest x mins. I found the one below, but it rounds up or down to the nearest x mins. Based on another value, I would either need to round it UP to the nearest half hour or hour.
CREATE FUNCTION [dbo].[RoundTime] (@Time DATETIME, @RoundToMin INT)
RETURNS DATETIME
AS
BEGIN
RETURN ROUND(CAST(CAST(CONVERT(VARCHAR,@Time,121) AS DATETIME) AS FLOAT) * (1440/@RoundToMin),0)/(1440/@RoundToMin)
END
GO
Change ROUND to CEILING and take away the “, 0” from the ROUND: