esta la funcion para calcular meses entre 2 fechas, me funciona bien..


CREATE OR REPLACE FUNCTION "public"."monthdiff" (_mesinicial integer, 
_annoinicial integer) RETURNS smallint AS
$body$
DECLARE
_mesactual SMALLINT;
_annoactual smallint;
_cantmes smallint;
_cantmestotal smallint;
_cantannototal smallint;
_totalmes smallint;
BEGIN
    _mesactual = date_part('month', current_date);
    _annoactual = date_part('year', current_date);
    if _mesinicial > _mesactual then
        _mesactual = _mesactual + 12;
        _cantmestotal = _mesactual - _mesinicial;
        _annoactual = _annoactual - 1;
    else
        _cantmestotal = _mesactual - _mesinicial;
    end if;                                      
    _cantannototal = _annoactual - _annoinicial;
    _cantannototal = _cantannototal * 12;
    _totalmes = _cantannototal + _cantmestotal;   
    return _totalmes-1;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
Date: Wed, 3 Mar 2010 22:34:51 -0300
Subject: [pgsql-es-ayuda] consulta resta fechas
From: [email protected]
To: [email protected]

Estimados les cuento, necesito obtener las personas que cumplan, de acuerdo a 
una determinada fecha, mas de 3 meses. Logre rescatar los dias de una resta de 
la siguiente forma 

select extract (day from (now()- pc_fecalta::timestamptz))::integer as fecha 
from pacientes p, prof_pac pp

where p.pc_cod = pp.pc_cod
and pf_cod=1 
and pc_alta =true

lo cual me devuelve 385. Alguien sabe como puedo determinar desde la misma 
consulta que estos 385 dyas son mayores a 3 mese, desde gracias

-- 
Sin más que decir se despide de Usted, muy atentamente 

Cesar Erices Vergara
Ingeniero en Gestión Informática
Analista de Sistema

Santiago - Chile
                                          
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. 
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

Responder a