I want to create a function in mysql 5.7 which receives two dates and checks if there is a difference. If yes it should add one day to the second date and return it. If not, it should return the date without any manipulation.
Unfortunately I receive a syntax error every time I want to save the function (using TablePlus with full rights).
My function:
CREATE FUNCTION `CheckCreatedAt`(timeStart DATETIME, timeEnd DATETIME) RETURNS datetime
BEGIN
DECLARE newDate DATETIME;
IF TIMESTAMPDIFF(DAY, timeStart, timeEnd) != 0
THEN
SET newDate = DATE_ADD(timeEnd, INTERVAL 1 DAY);
ELSE
SET newDate = timeEnd;
END IF;
RETURN newDate;
END
The error-message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ELSE SET newDate = timeEnd; END IF;
RETURN newDate; END' at line 6