Re: DateAdd function ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jeff Eckermann" <jeff_eckermann(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: DateAdd function ?
Date: 2005-04-19 14:37:06
Message-ID: 21421.1113921426@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Jeff Eckermann" <jeff_eckermann(at)yahoo(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message KÖPFERL Robert 2005-04-19 14:43:41 Re: trying to do an update a bit confused.
Previous Message Jeff Eckermann 2005-04-19 14:25:43 Re: Query about SQL in PostgreSQL