Thread: Arithmetic operation on DATE

Arithmetic operation on DATE

From
"macky"
Date:
is it possible to add a date datatype column to a number resulting to a
date......


theoretically it should do this,,,

X is in months

date + X = date

-->  2001-08-20 + 6 = 2002-02-20

----------------------------------------------------------------------
The information contained in this message (including any attachments)
is confidential and intended solely for the attention and use of the
named addressee(s). It must not be copied, distributed nor disclosed
to any person. If you are not the intended recipient, please delete
it from your system and notify sender immediately. Any disclosure,
copying or distribution thereof or any action taken or omitted to be
taken in reliance thereon is prohibited and may be unlawful.
----------------------------------------------------------------------



Re: Arithmetic operation on DATE

From
Christopher Sawtell
Date:
On Mon, 13 Aug 2001 21:48, macky wrote:
> is it possible to add a date datatype column to a number resulting to a
> date......

chris=# select date(CURRENT_TIMESTAMP);
    date
------------
 2001-08-13
(1 row)

chris=# select date(CURRENT_TIMESTAMP) + '6 @days'::interval;
        ?column?
------------------------
 2001-08-19 00:00:00+12
(1 row)

chris=# select date(date(CURRENT_TIMESTAMP) + '6 @days'::interval);
    date
------------
 2001-08-19
(1 row)

That what you want?

> theoretically it should do this,,,
>
> X is in months
>
> date + X = date
>
> -->  2001-08-20 + 6 = 2002-02-20
>
> ----------------------------------------------------------------------
> The information contained in this message (including any attachments)
> is confidential and intended solely for the attention and use of the
> named addressee(s). It must not be copied, distributed nor disclosed
> to any person. If you are not the intended recipient, please delete
> it from your system and notify sender immediately. Any disclosure,
> copying or distribution thereof or any action taken or omitted to be
> taken in reliance thereon is prohibited and may be unlawful.
> ----------------------------------------------------------------------
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

Re: Arithmetic operation on DATE

From
Karel Zak
Date:
On Mon, Aug 13, 2001 at 05:48:57PM +0800, macky wrote:
> is it possible to add a date datatype column to a number resulting to a
> date......
>
>
> theoretically it should do this,,,
>
> X is in months
>
> date + X = date
>
> -->  2001-08-20 + 6 = 2002-02-20

test=# select '2001-08-20'::date + '6months'::interval;
        ?column?
------------------------
 2002-02-20 00:00:00+01
(1 row)


 ..see docs about the "interval" datetype.

            Karel

--
 Karel Zak  <zakkr@zf.jcu.cz>
 http://home.zf.jcu.cz/~zakkr/

 C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

Re: [NOVICE] Arithmetic operation on DATE

From
"Jason Wong"
Date:
I know you can do it for days, thus:

   expires = CURRENT_TIMESTAMP + 10

would be 10 days from now. Don't know about months though.

HTH
--
Jason Wong
Gremlins Associates
www.gremlins.com.hk


----- Original Message -----
From: macky <macky@edsamail.com>
To: <pgsql-novice@postgresql.org>; <pgsql-sql@postgresql.org>
Sent: Monday, August 13, 2001 5:48 PM
Subject: [NOVICE] Arithmetic operation on DATE


> is it possible to add a date datatype column to a number resulting to a
> date......
>
>
> theoretically it should do this,,,
>
> X is in months
>
> date + X = date
>
> -->  2001-08-20 + 6 = 2002-02-20
>