Thread: interval +variable

interval +variable

From
"Fatih Cerit"
Date:
Dear all

Is there anyone at there who knows howto use dateadd in pgsql. I have a 
problem in my function that is like this ;

Select into futuredate now() + interval '30 days';  <- this is ok
but how can I use a variable intead of '30 days'    :(

Thanks 



Re: interval +variable

From
Michael Fuhr
Date:
On Wed, Mar 09, 2005 at 10:58:05AM +0200, Fatih Cerit wrote:

> Is there anyone at there who knows howto use dateadd in pgsql. I have a 
> problem in my function that is like this ;
> 
> Select into futuredate now() + interval '30 days';  <- this is ok
> but how can I use a variable intead of '30 days'    :(

Are you looking for something like this?

ndays := 30;
SELECT INTO futuredate now() + ndays * interval'1 day';

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


Re: interval +variable

From
Bruno Wolff III
Date:
On Wed, Mar 09, 2005 at 10:58:05 +0200, Fatih Cerit <fatih@intersan.com.tr> wrote:
> Dear all
> 
> Is there anyone at there who knows howto use dateadd in pgsql. I have a 
> problem in my function that is like this ;
> 
> Select into futuredate now() + interval '30 days';  <- this is ok
> but how can I use a variable intead of '30 days'    :(

A better solution may to be to use the date type instead of the timestamp type.
Then you can just add an integer number to the date. You also don't have
to worry about daylight savings time changes.


Re: interval +variable

From
"ALÝ ÇELÝK"
Date:
+ '1 days'::interval

""Fatih Cerit"" <fatih@intersan.com.tr>, haber iletisinde �unlar� 
yazd�:008a01c52486$1c1c9520$bb41ccd5@cerit...
> Dear all
>
> Is there anyone at there who knows howto use dateadd in pgsql. I have a 
> problem in my function that is like this ;
>
> Select into futuredate now() + interval '30 days';  <- this is ok
> but how can I use a variable intead of '30 days'    :(
>
> Thanks
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>      joining column's datatypes do not match
>