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 9829432AA24 for ; Mon, 11 Oct 2004 10:21:42 +0100 (BST) 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 32506-08 for ; Mon, 11 Oct 2004 09:21:35 +0000 (GMT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id 16CAC32A9E2 for ; Mon, 11 Oct 2004 10:21:33 +0100 (BST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 4.42) id 1CGwN3-000LFS-0I; Mon, 11 Oct 2004 09:21:33 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id B608D1636E; Mon, 11 Oct 2004 10:21:31 +0100 (BST) Message-ID: <416A509B.5000900@archonet.com> Date: Mon, 11 Oct 2004 10:21:31 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Gaetano Mendola Cc: sreejith s , pgsql-sql@postgresql.org Subject: Re: SQL doubt - Date Add References: <5d14ecf904101007197d0acbbf@mail.gmail.com> <41694906.3030408@bigfoot.com> In-Reply-To: <41694906.3030408@bigfoot.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/72 X-Sequence-Number: 19175 Gaetano Mendola wrote: > sreejith s wrote: > >> Hi friends, >> I problem is i want to add a specified no. of years to a >> given date >> ie, 12/12/2004 + 5 = 12/12/2009. This has to be done via sql. Any >> predefined function there for the same. or v have split the yr and >> then add. >> Sreejith >> > > # select '2004-12-12'::date + 5 * '1 year'::interval; > ?column? > --------------------- > 2009-12-12 00:00:00 > (1 row) But be aware of... richardh=# SELECT '2004-02-28'::date + '1 year'::interval; ?column? --------------------- 2005-02-28 00:00:00 (1 row) richardh=# SELECT '2004-02-29'::date + '1 year'::interval; ?column? --------------------- 2005-02-28 00:00:00 (1 row) richardh=# SELECT '2004-02-29'::date + '4 years'::interval; ?column? --------------------- 2008-02-29 00:00:00 (1 row) -- Richard Huxton Archonet Ltd