"Zlatko Matiæ" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am currently migrating from MSDE to PostgreSQL and have to rewrite the 
>function that is calculating next date of sampling...
> In MSDE there is a DateAdd function. I can't find the appropriate function 
> in postgre. Can you help me?

There is no "dateadd" function in PostgreSQL, but you can write your own 
easily enough.  The following should give you an idea of the logic you can 
use:

jeck=# select current_date;
    date
------------
 2005-04-19
(1 row)

jeck=# select current_date + cast('1 day' as interval);
        ?column?
------------------------
 2005-04-20 00:00:00-05
(1 row)

jeck=# select current_date + cast('3 months' as interval);
        ?column?
------------------------
 2005-07-19 00:00:00-05
(1 row)

jeck=# select current_date + 3 * cast('1 month' as interval);
        ?column?
------------------------
 2005-07-19 00:00:00-05
(1 row)


> The function in MSDE is the following:
>
> ALTER FUNCTION dbo.slisp
> (
> @UCESTALOST_BROJ int,
> @UCESTALOST_JEDINICA nvarchar (50),
> @DATUM_ISPITIVANJA datetime
> )
> RETURNS datetime
> AS
> BEGIN
>  DECLARE @SLISP datetime
>   IF @UCESTALOST_JEDINICA='m' SET @SLISP=DATEADD(month, @UCESTALOST_BROJ, 
> MAX(@DATUM_ISPITIVANJA))
>   IF @UCESTALOST_JEDINICA='g' SET @SLISP=DATEADD(year, @UCESTALOST_BROJ, 
> MAX(@DATUM_ISPITIVANJA))
>   IF @UCESTALOST_JEDINICA='d' SET @SLISP=DATEADD(day, @UCESTALOST_BROJ, 
> MAX(@DATUM_ISPITIVANJA))
>  RETURN @SLISP
> END
>
> Thanks.
> 



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to