pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Gaetano Mendola <mendola@bigfoot.com>
Cc: sreejith s <getsreejith@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL doubt - Date Add
Date: Mon, 11 Oct 2004 10:21:31 +0100
Message-ID: <416A509B.5000900@archonet.com> (raw)
In-Reply-To: <41694906.3030408@bigfoot.com>
References: <5d14ecf904101007197d0acbbf@mail.gmail.com>
	<41694906.3030408@bigfoot.com>

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



view thread (4+ messages)

Message-ID: <416A509B.5000900@archonet.com>
Permalink:  ../416A509B.5000900@archonet.com/
Also on:    postgresql.org/message-id/416A509B.5000900@archonet.com

 · 

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: dev@archonet.com, mendola@bigfoot.com, getsreejith@gmail.com
  Subject: Re: SQL doubt - Date Add
  In-Reply-To: <416A509B.5000900@archonet.com>

* 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