Last active
December 1, 2015 05:47
-
-
Save yogonza524/63ca87cad5535007746b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT current_date - (timestamp '2015-11-29')::date; | |
CREATE OR REPLACE FUNCTION betweenDays(fecha date) | |
RETURNS integer AS $$ | |
DECLARE | |
output integer; | |
BEGIN | |
IF fecha IS NOT NULL THEN | |
SELECT current_date - fecha INTO output; | |
ELSE | |
RAISE EXCEPTION 'La fecha es nula'; | |
END IF; | |
RETURN output; | |
END; | |
$$ | |
LANGUAGE PLPGSQL |
La función betweenDays(fecha) retorna el resultado de hacer la diferencia entre la fecha actual y la fecha pasada como parametro. Si la fecha parametro es nula entonces lanza una excepción.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Esta selección me permite obtener la diferencia en dias entre dos fechas. Los posibles resultados pueden ser positivos, cero o negativos.