From: | Ramón Alberto Bruening González <albertobruening(at)hotmail(dot)com> |
---|---|
To: | <caerices(at)gmail(dot)com>, <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | RE: consulta resta fechas |
Date: | 2010-03-04 14:41:48 |
Message-ID: | SNT137-w5238BD1E1449BEBE5D7D04A2390@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
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: caerices(at)gmail(dot)com
To: pgsql-es-ayuda(at)postgresql(dot)org
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
From | Date | Subject | |
---|---|---|---|
Next Message | Grover Navia | 2010-03-04 15:14:10 | RE:Ayuda con funcion |
Previous Message | Cesar Erices | 2010-03-04 14:40:28 | Re: consulta resta fechas |