I am new to mysql and I have this problem with my code
CREATE FUNCTION fnejEdad_Obtener
(
p_fechaNacimiento date,
p_fechaHoy date
)
RETURNS int
BEGIN
declare v_edad int;
set v_edad = TIMESTAMPDIFF (year,p_fechaNacimiento, p_fechaHoy);
if (DATEPART(month, p_fechaNacimiento) > DATEPART(month,p_fechaHoy))
then
set v_edad = v_edad - 1;
else if
(DATEPART
(month, p_fechaNacimiento) <= DATEPART
(month,p_fechaHoy)) and
(DATEPART
(DAY, p_fechaNacimiento) > DATEPART
(DAY,p_fechaHoy))
then
set v_edad = v_edad - 1;
end
if;
IF v_edad < 0 THEN
SET v_edad = 0;
END
IF; -- > update
RETURN v_edad;
END;
Your function has to be as follows. Elseif has be to be written together.
DELIMITER //
CREATE FUNCTION fnejEdad_Obtener
(p_fechaNacimiento date,p_fechaHoy date)
RETURNS int
BEGIN
declare v_edad int;
set v_edad = TIMESTAMPDIFF(year,p_fechaNacimiento, p_fechaHoy);
if (DATEPART(month, p_fechaNacimiento) > DATEPART(month,p_fechaHoy)) then
set v_edad = v_edad - 1;
elseif
(DATEPART(month, p_fechaNacimiento) <= DATEPART(month,p_fechaHoy)) and
(DATEPART(DAY, p_fechaNacimiento) > DATEPART(DAY,p_fechaHoy)) then
set v_edad = v_edad - 1;
end if;
IF v_edad < 0 THEN
SET v_edad = 0;
END IF; -- > update
RETURN v_edad;
END
//
DELIMITER ;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments