Thread: ...

...

From
apratim sharma
Date:
hi,
 
Can anybody tell how to add an integer to a date inside postgres query.
 
i'm using postgres 7.3
 
when i give    select cast(now() as date) it gives the current date,
now i want to select a date say after 10 days.
i'm giving select cast(now() as date) +10 ; it gives error can't typecast date to int
 
what to do???
 
please help me
 
Apratim
 



Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more

Re:

From
"Jordan S. Jones"
Date:
To increment days:

SELECT cast(now() + interval '10 day' as date);

Otherwise I suggest you take a look at http://www.postgresql.com/docs/view.php?version=7.3&idoc=1&file=functions-datetime.html

apratim sharma wrote:
hi,
 
Can anybody tell how to add an integer to a date inside postgres query.
 
i'm using postgres 7.3
 
when i give    select cast(now() as date) it gives the current date,
now i want to select a date say after 10 days.
i'm giving select cast(now() as date) +10 ; it gives error can't typecast date to int
 
what to do???
 
please help me
 
Apratim
 



Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more

Re:

From
Tom Lane
Date:
apratim sharma <hiapra@yahoo.com> writes:
> hi, Can anybody tell how to add an integer to a date inside postgres
> query. i'm using postgres 7.3 when i give    select cast(now() as
> date) it gives the current date, now i want to select a date say after
> 10 days. i'm giving select cast(now() as date) +10 ; it gives error
> can't typecast date to int what to do??? please help me Apratim

Works for me:

regression=# select cast(now() as date) +10 ;
  ?column?
------------
 2003-04-23
(1 row)

What PG version are you using, and are you sure that's exactly the
query you're issuing?

            regards, tom lane