pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedArithmetic operation on DATE
8+ messages / 6 participants
[nested] [flat]
* Arithmetic operation on DATE
@ 2001-08-13 09:38 macky <macky@edsamail.com>
2001-08-13 10:02 ` Re: [SQL] Arithmetic operation on DATE Antti Linno <alligator@all.ee>
2001-08-13 10:03 ` Re: [SQL] Arithmetic operation on DATE Christopher Sawtell <csawtell@paradise.net.nz>
0 siblings, 2 replies; 8+ messages in thread
From: macky @ 2001-08-13 09:38 UTC (permalink / raw)
To: pgsql-sql; pgsql-novice@postgresql.org
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.
----------------------------------------------------------------------
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] Arithmetic operation on DATE
2001-08-13 09:38 Arithmetic operation on DATE macky <macky@edsamail.com>
@ 2001-08-13 10:02 ` Antti Linno <alligator@all.ee>
1 sibling, 0 replies; 8+ messages in thread
From: Antti Linno @ 2001-08-13 10:02 UTC (permalink / raw)
To: macky <macky@edsamail.com>; +Cc: pgsql-sql; pgsql-novice@postgresql.org
Ok, so here's my small knowledge on this matter
select date(date('2001-08-20')+interval('6 months'));
date
------------
2002-02-20
I'm sure there's more elegant and shorter ways of doing this, but a quick
answer, maybe you're stuck somewhere :)
Antti
Tested it on 7.0.2.
On Mon, 13 Aug 2001, 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
>
>
>
>
>
>
> ----------------------------------------------------------------------
> 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 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] Arithmetic operation on DATE
2001-08-13 09:38 Arithmetic operation on DATE macky <macky@edsamail.com>
@ 2001-08-13 10:03 ` Christopher Sawtell <csawtell@paradise.net.nz>
1 sibling, 0 replies; 8+ messages in thread
From: Christopher Sawtell @ 2001-08-13 10:03 UTC (permalink / raw)
To: macky <macky@edsamail.com>; pgsql-sql; pgsql-novice@postgresql.org
On Mon, 13 Aug 2001 21:38, macky wrote:
> is it possible to add a date datatype column to a number resulting to a
> date......
chris=# select date(date(CURRENT_TIMESTAMP) + '6 @months'::interval);
date
------------
2002-02-13
(1 row)
More of 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 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 8+ messages in thread
* Arithmetic operation on DATE
@ 2001-08-13 09:48 macky <macky@edsamail.com>
2001-08-13 10:01 ` Re: [SQL] Arithmetic operation on DATE Christopher Sawtell <csawtell@paradise.net.nz>
2001-08-13 10:02 ` Re: Arithmetic operation on DATE Jason Wong <postgresql@gremlins.com.hk>
2001-08-13 10:11 ` Re: [SQL] Arithmetic operation on DATE Karel Zak <zakkr@zf.jcu.cz>
0 siblings, 3 replies; 8+ messages in thread
From: macky @ 2001-08-13 09:48 UTC (permalink / raw)
To: pgsql-novice@postgresql.org; pgsql-sql
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.
----------------------------------------------------------------------
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] Arithmetic operation on DATE
2001-08-13 09:48 Arithmetic operation on DATE macky <macky@edsamail.com>
@ 2001-08-13 10:01 ` Christopher Sawtell <csawtell@paradise.net.nz>
2 siblings, 0 replies; 8+ messages in thread
From: Christopher Sawtell @ 2001-08-13 10:01 UTC (permalink / raw)
To: macky <macky@edsamail.com>; pgsql-novice@postgresql.org; pgsql-sql
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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Arithmetic operation on DATE
2001-08-13 09:48 Arithmetic operation on DATE macky <macky@edsamail.com>
@ 2001-08-13 10:02 ` Jason Wong <postgresql@gremlins.com.hk>
2001-08-14 15:30 ` Re: [SQL] Re: Arithmetic operation on DATE Josh Berkus <josh@agliodbs.com>
2 siblings, 1 reply; 8+ messages in thread
From: Jason Wong @ 2001-08-13 10:02 UTC (permalink / raw)
To: macky <macky@edsamail.com>; pgsql-novice@postgresql.org; pgsql-sql
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
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] Re: Arithmetic operation on DATE
2001-08-13 09:48 Arithmetic operation on DATE macky <macky@edsamail.com>
2001-08-13 10:02 ` Re: Arithmetic operation on DATE Jason Wong <postgresql@gremlins.com.hk>
@ 2001-08-14 15:30 ` Josh Berkus <josh@agliodbs.com>
0 siblings, 0 replies; 8+ messages in thread
From: Josh Berkus @ 2001-08-14 15:30 UTC (permalink / raw)
To: Jason Wong <postgresql@gremlins.com.hk>; macky <macky@edsamail.com>; pgsql-novice@postgresql.org
Jason, Macky,
> expires = CURRENT_TIMESTAMP + 10
>
> would be 10 days from now. Don't know about months though.
That's almost correct. Try:
expires := current_timestamp + '10 days'::INTERVAL
For macky's question:
expires := current_timestamp + '6 months'::INTERVAL
I'll be posting a FAQ on data/time datatypes in PostgreSQL soon.
-Josh Berkus
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] Arithmetic operation on DATE
2001-08-13 09:48 Arithmetic operation on DATE macky <macky@edsamail.com>
@ 2001-08-13 10:11 ` Karel Zak <zakkr@zf.jcu.cz>
2 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2001-08-13 10:11 UTC (permalink / raw)
To: macky <macky@edsamail.com>; +Cc: pgsql-novice@postgresql.org; pgsql-sql
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
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2001-08-14 15:30 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-13 09:38 Arithmetic operation on DATE macky <macky@edsamail.com>
2001-08-13 10:02 ` Antti Linno <alligator@all.ee>
2001-08-13 10:03 ` Christopher Sawtell <csawtell@paradise.net.nz>
2001-08-13 09:48 Arithmetic operation on DATE macky <macky@edsamail.com>
2001-08-13 10:01 ` Christopher Sawtell <csawtell@paradise.net.nz>
2001-08-13 10:02 ` Jason Wong <postgresql@gremlins.com.hk>
2001-08-14 15:30 ` Josh Berkus <josh@agliodbs.com>
2001-08-13 10:11 ` Karel Zak <zakkr@zf.jcu.cz>
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