From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Eckermann <jeff_eckermann@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: DateAdd function ?
Date: Tue, 19 Apr 2005 10:37:06 -0400
Message-ID: <21421.1113921426@sss.pgh.pa.us> (raw)
In-Reply-To: <d4348v$30ii$2@news.hub.org>
References: <d42nl1$7al$1@ss405.t-com.hr>
<d4348v$30ii$2@news.hub.org>
"Jeff Eckermann" <jeff_eckermann@yahoo.com> writes:
> 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 + cast('1 day' as interval);
Alternatively, maybe you want to use the date-plus/minus-integer operators.
regression=# select current_date;
date
------------
2005-04-19
(1 row)
regression=# select current_date + 1;
?column?
------------
2005-04-20
(1 row)
regression=# select current_date - 1;
?column?
------------
2005-04-18
(1 row)
There isn't really a date-plus-interval operator --- what's happening
there is the date is implicitly promoted to timestamp and then
timestamp-plus-interval is used. You might want this if you want to
add symbolic quantities like '2 months' or '1 year', but for small
integer numbers of days, the integer operations are faster and simpler
to use.
regards, tom lane
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: tgl@sss.pgh.pa.us, jeff_eckermann@yahoo.com
Subject: Re: DateAdd function ?
In-Reply-To: <21421.1113921426@sss.pgh.pa.us>
* 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