Never rtied this but instead of fetching the time and startdate from the table, try sending them to the function as parameters. Something like:
ALTER FUNCTION [dbo].[CalculateDelay]
IF ( @IsReturned = 0 )
DECLARE @delay INT = ( SELECT ( DATEDIFF(minute,
If that doesn't help, I'd suggest to move the calculation to a trigger.