This function should do what you want. It relies on MySQL treating boolean results as either 1 or 0 in a numeric context, thus the MAX
call effectively becomes an OR
of all the conditions.
CREATE FUNCTION check_activity(project_id INT, check_date DATE)
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
RETURN (SELECT MAX(check_date BETWEEN ActiveFrom AND ActiveTo) FROM projects WHERE ProjId = project_id);
END
SELECT check_activity(20, '2018-01-10'), check_activity(20, '2018-02-01')
Output
check_activity(20, '2018-01-10') check_activity(20, '2018-02-01')
1 0
3
solved Is a date within some of periods [closed]