[GENERAL] How to return an INT4 subtracting dates?

2010-06-09 Thread Andre Lopes
Hi,

I need to return an int4 subtracting two dates, but returns me an interval.

select
end_date - now() as interger_number
from hist_anuncios

How to return an integer out of this?


Best Regards,


Re: [GENERAL] How to return an INT4 subtracting dates?

2010-06-09 Thread Pavel Stehule
Hello

2010/6/9 Andre Lopes :
> Hi,
>
> I need to return an int4 subtracting two dates, but returns me an interval.
>
> select
> end_date - now() as interger_number
> from hist_anuncios
>
> How to return an integer out of this?
>
>
> Best Regards,
>
>

postgres=# select '2010-06-18'::date - CURRENT_DATE;
 ?column?
--
9
(1 row)

Regards

pavel Stehule

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] How to return an INT4 subtracting dates?

2010-06-09 Thread Raymond O'Donnell
On 09/06/2010 11:57, Andre Lopes wrote:
> Hi,
> 
> I need to return an int4 subtracting two dates, but returns me an interval.
> 
> select
> end_date - now() as interger_number
> from hist_anuncios
> 
> How to return an integer out of this?

Hmmm, according to the docs, subtracting dates returns an integer:

  http://www.postgresql.org/docs/8.4/static/functions-datetime.html

Try "current_date", which gives you a date, instead of "now", which
gives you a timestamp.

Ray.


-- 
Raymond O'Donnell :: Galway :: Ireland
r...@iol.ie

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general