X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 33EF0533AA for ; Tue, 19 Apr 2005 11:23:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98886-01 for ; Tue, 19 Apr 2005 14:23:29 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2870153397 for ; Tue, 19 Apr 2005 11:23:28 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id B287130952; Tue, 19 Apr 2005 16:22:29 +0200 (MET DST) From: "Jeff Eckermann" X-Newsgroups: pgsql.sql Subject: Re: DateAdd function ? Date: Tue, 19 Apr 2005 09:23:30 -0500 Organization: Hub.Org Networking Services Lines: 62 Message-ID: References: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.463 tagged_above=0 required=5 tests=AWL, FORGED_YAHOO_RCVD, PRIORITY_NO_NAME, UPPERCASE_25_50 X-Spam-Level: *** X-Archive-Number: 200504/289 X-Sequence-Number: 21182 "Zlatko Matiæ" 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. >