WITH CTE AS (
SELECT *, IIF(datepart(hour, START_MOMENT) >= 18,
START_MOMENT,
dateadd(HOUR, 18, convert(smalldatetime, convert(date, START_MOMENT)))) AS New_start,
IIF(datediff(DAY, START_MOMENT, STOP_MOMENT) = 0,
STOP_MOMENT,
dateadd(DAY, 1, convert(date, START_MOMENT))) AS New_end
FROM tblTest
)
SELECT *, datediff(MINUTE, New_start, New_end)
FROM CTE
Had you posted the sample data as INSERT statements, I would have verified that this produce the expected result.