Thread: Dateadd

Dateadd

From
"Ligia Pimentel"
Date:
I need to know if there is a sql function implemented in postgres that gives
me a date plus any number of days, months or years (the traditional dateadd
function) or how to do it in sql?

Thanks in advance for any help

Ligia




Re: Dateadd

From
Stephan Szabo
Date:
On Wed, 2 May 2001, Ligia Pimentel wrote:

> I need to know if there is a sql function implemented in postgres that gives
> me a date plus any number of days, months or years (the traditional dateadd
> function) or how to do it in sql?

Just add a date and an interval.  Something like:
date + '1 day'::interval



Re: Dateadd

From
Cliff Crawford
Date:
* Ligia Pimentel <lmpimentel@yahoo.com> menulis:
> I need to know if there is a sql function implemented in postgres that gives
> me a date plus any number of days, months or years (the traditional dateadd
> function) or how to do it in sql?

cepat=# select '01-01-00'::date + '2 months 10 days'::interval;      ?column?        
------------------------
2000-03-11 00:00:00-05
(1 row)



-- 
Cliff Crawford   http://www.sowrong.org/
birthday party cheesecake jellybean BOOM


Re: Dateadd

From
"Josh Berkus"
Date:
Folks,
FYI - this difference in syntax is because PostgreSQL implements real
SQL operators (i.e. what the operator does and what arguments it takes
depend on the data types involved) and Microsoft does not (in MS SQL,
operators mean the same thing for almost all data types).
Speaking of which, why doesn't PostgreSQL allow the use of "+" between
two VARCHARs to mean the same as "||" ?  Is there an addition operation
for PgSQL for VARCHAR other than concatination?

-Josh


> > I need to know if there is a sql function implemented in postgres
> that gives
> > me a date plus any number of days, months or years (the traditional
> dateadd
> > function) or how to do it in sql?


______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


Re: Dateadd

From
Tom Lane
Date:
"Josh Berkus" <josh@agliodbs.com> writes:
> Speaking of which, why doesn't PostgreSQL allow the use of "+" between
> two VARCHARs to mean the same as "||" ?

You mean, other than the fact that "||" is the SQL-standard string
concatenation operator and "+" isn't?

I'm not eager to follow the pied pipers from Redmond down the garden
path to completely standards-ignorant products.  *Someone's* got to
stick up for standards compliance.  Microsoft has a vested interest in
locking people into their code via gratuitously nonstandard notations
... but let's not be like them.

There was some talk recently of putting together packages of function
and operator definitions to ease portability from other DBMSes to PG.
I'd have no objection to including "+ as string concatenation" in a
set of operators that're clearly marked as MS-SQL-isms.  But I don't
think we'd do the world any favor by adopting a clearly nonstandard
notation as part of our standard operator set.
        regards, tom lane


Re: Dateadd

From
Bruce Momjian
Date:
> There was some talk recently of putting together packages of function
> and operator definitions to ease portability from other DBMSes to PG.
> I'd have no objection to including "+ as string concatenation" in a
> set of operators that're clearly marked as MS-SQL-isms.  But I don't
> think we'd do the world any favor by adopting a clearly nonstandard
> notation as part of our standard operator set.

Now that someone else thinks this is a good idea, I have added to the
TODO list:
* Allow plug-in modules to emulate features from other databases

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026