I have a funtion in MYSQL to substruct days from a date.
This function seamsto work but some dates it times out.
This is my function
CREATE DEFINER=`root`@`localhost` FUNCTION `Calculater`(intrval int, req date) RETURNS date DETERMINISTIC BEGIN declare calculated date; declare added int default 0; Lbl_Loop: Loop IF added=intrval then leave lbl_loop; End IF; set calculated = DATE_SUB(req,interval 1 day); IF weekday(calculated)<5 then set added= added+1; End If; end loop; RETURN calculated; END
If I do select Calculater(1,"2020-02-04"); it works, but select Calculater(1,"2020-02-02"); it runs for a few seconds and My SQL times out.
Thanks in advance.