I am creating a function in PostgreSQL to find the difference between 2 dates and setting it as an INT. I keep getting a syntax error. I know there is no DATEDIFF option in PostgreSQL and I have to subtract one from the other. Here is my code
CREATE FUNCTION calculate_rental_duration(
rental_date DATE,
return_date DATE)
RETURNS INT
LANGUAGE plpgsql
AS
$$
DECLARE rental_duration INT;
BEGIN
SET rental_duration = (return_date - rental_date);
RETURN rental_duration;
END;
$$
Why do I keep getting a syntax error right before = (return_date – rental_date);?
I tried using DATEDIFF first but discovered that PostgreSQL has no DATEDIFF option and that I need to subtract rental_date from return_date to get the answer I am looking for. I am new to PostgreSQL but have an understanding of SQL (basics anyway). I tried dropping the parenthesis but that didn’t work either.