pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Eckermann <jeff_eckermann@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: DateAdd function ?
Date: Tue, 19 Apr 2005 09:23:30 -0500
Message-ID: <d4348v$30ii$2@news.hub.org> (raw)
References: <d42nl1$7al$1@ss405.t-com.hr>


"Zlatko MatiƦ" <zlatko.matic1@sb.t-com.hr> wrote in message 
news:d42nl1$7al$1@ss405.t-com.hr...
>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.
> 





view thread (2+ messages)  latest in thread

Message-ID: <d4348v$30ii$2@news.hub.org>
Permalink:  ../d4348v$30ii$2@news.hub.org/
Also on:    postgresql.org/message-id/d4348v$30ii$2@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jeff_eckermann@yahoo.com
  Subject: Re: DateAdd function ?
  In-Reply-To: <d4348v$30ii$2@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox