PostgreSQL - Months_between para postgres

 
Vista:

Months_between para postgres

Publicado por Jesus Lobaton (1 intervención) el 09/10/2006 21:07:43
Hola, aqui le dejo una funcion que permite utilizar la funcion Months_between de Oracle en postgres, ya que me canse de buscarlo por google y no consegui una solucion inmediata, espero que le sirvan....

CREATE OR REPLACE FUNCTION "ESQUEMA"."months_between" (date, date) RETURNS integer AS
$body$
DECLARE
mes INTEGER;
mes1 INTEGER;
ano INTEGER;
begin
mes=extract(month from (age($1,$2)));
ano=extract(year from (age($1,$2)));

mes1=abs((ano*12) + mes);
return mes1;
end
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

y para llamarla o ejecutarla seria:

select months_between(campo_fecha1,campo_fecha2) as tabla

P.D: Esta funcion devuelve las diferencia de meses entre dos fechas.

Suerte......
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Months_between para postgres

Publicado por Gerardo (1 intervención) el 20/01/2009 21:17:11
oye muchas gracias esto andaba buscando :D ............ y funciona muy bien
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar