BEGIN
	DECLARE freedays int;
	SET freedays = 0;

	SET @x = DATEDIFF(end_date, start_date);
	IF @x<0 THEN
		SET @m = start_date;
		SET start_date = end_date;
		SET end_date = @m;
		SET @m = -1;
	ELSE
		SET @m = 1;
	END IF;
	SET @x = abs(@x) + 1;
	/* days in first week */
	SET @w1 = WEEKDAY(start_date)+1;
	SET @wx1 = 8-@w1;
	IF @w1>5 THEN
		SET @w1 = 0;
	ELSE
		SET @w1 = 6-@w1;
	END IF;
	/* days in last week */
	SET @wx2 = WEEKDAY(end_date)+1;
	SET @w2 = @wx2;
	IF @w2>5 THEN
		SET @w2 = 5;
	END IF;
	/* summary */
	SET @weeks = (@x-@wx1-@wx2)/7;
	SET @noweekends = (@weeks*5)+@w1+@w2;

	SELECT count(*) INTO freedays FROM sis_course_holiday WHERE holiday_date BETWEEN start_date AND end_date;

	SET @result = @noweekends-freedays;
	RETURN @result*@m;
END