pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedDateadd
8+ messages / 8 participants
[nested] [flat]
* Dateadd
@ 2001-05-03 00:55 Ligia Pimentel <lmpimentel@yahoo.com>
2001-05-04 14:20 ` Re: Dateadd Vivek Khera <khera@kcilink.com>
2001-05-04 21:34 ` Re: Dateadd Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-05-04 21:58 ` Re: Dateadd Cliff Crawford <cjc26@cornell.edu>
0 siblings, 3 replies; 8+ messages in thread
From: Ligia Pimentel @ 2001-05-03 00:55 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
@ 2001-05-04 14:20 ` Vivek Khera <khera@kcilink.com>
2 siblings, 0 replies; 8+ messages in thread
From: Vivek Khera @ 2001-05-04 14:20 UTC (permalink / raw)
To: pgsql-sql
>>>>> "LP" == Ligia Pimentel <lmpimentel@yahoo.com> writes:
LP> I need to know if there is a sql function implemented in postgres
LP> that gives me a date plus any number of days, months or years (the
LP> traditional dateadd function) or how to do it in sql?
Here's what I use:
select CURRENT_DATE + '4 DAYS'::interval;
Just cast your "interval" from a string to an interval type, then add
it to your date value.
I doubt this is portable. What "tradition" provides for a dateadd()
function?
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D. Khera Communications, Inc.
Internet: khera@kciLink.com Rockville, MD +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
@ 2001-05-04 21:34 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2 siblings, 0 replies; 8+ messages in thread
From: Stephan Szabo @ 2001-05-04 21:34 UTC (permalink / raw)
To: Ligia Pimentel <lmpimentel@yahoo.com>; +Cc: pgsql-sql
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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
@ 2001-05-04 21:58 ` Cliff Crawford <cjc26@cornell.edu>
2001-05-05 21:44 ` Re: Dateadd Josh Berkus <josh@agliodbs.com>
2 siblings, 1 reply; 8+ messages in thread
From: Cliff Crawford @ 2001-05-04 21:58 UTC (permalink / raw)
To: Ligia Pimentel <lmpimentel@yahoo.com>; +Cc: pgsql-sql
* 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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
2001-05-04 21:58 ` Re: Dateadd Cliff Crawford <cjc26@cornell.edu>
@ 2001-05-05 21:44 ` Josh Berkus <josh@agliodbs.com>
2001-05-06 05:00 ` Re: Dateadd Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Josh Berkus @ 2001-05-05 21:44 UTC (permalink / raw)
To: pgsql-sql
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 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: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
2001-05-04 21:58 ` Re: Dateadd Cliff Crawford <cjc26@cornell.edu>
2001-05-05 21:44 ` Re: Dateadd Josh Berkus <josh@agliodbs.com>
@ 2001-05-06 05:00 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-05-07 17:04 ` Re: Dateadd Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2001-05-06 05:00 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-sql
"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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Dateadd
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
2001-05-04 21:58 ` Re: Dateadd Cliff Crawford <cjc26@cornell.edu>
2001-05-05 21:44 ` Re: Dateadd Josh Berkus <josh@agliodbs.com>
2001-05-06 05:00 ` Re: Dateadd Tom Lane <tgl@sss.pgh.pa.us>
@ 2001-05-07 17:04 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Bruce Momjian @ 2001-05-07 17:04 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-sql
> 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, Pennsylvania 19026
^ permalink raw reply [nested|flat] 8+ messages in thread
* DATEADD
@ 2004-02-23 08:17 Sumita Biswas <sbiswas@cisco.com>
0 siblings, 0 replies; 8+ messages in thread
From: Sumita Biswas @ 2004-02-23 08:17 UTC (permalink / raw)
To: 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
I had the following code in my MSSQL Stored Procedure:
--Adding 23Hrs 59Mins 59Secs to the ToDate(@ld_ToDate is
DateTime datatype)
SET @ld_ToDate = DATEADD(ss, 86399, @ld_ToDate);
I have changed it to the following for Postgres Function:
--Adding 23Hrs 59Mins 59Secs to the ToDate
--Here $2 is an input variable(timestamp datatype)
lv_ToDate := $2 + interval ''86399 seconds'';
Does this make sense?
Any pointers appreciated.
Thanks,
Sumita
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2004-02-23 08:17 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-03 00:55 Dateadd Ligia Pimentel <lmpimentel@yahoo.com>
2001-05-04 14:20 ` Vivek Khera <khera@kcilink.com>
2001-05-04 21:34 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-05-04 21:58 ` Cliff Crawford <cjc26@cornell.edu>
2001-05-05 21:44 ` Josh Berkus <josh@agliodbs.com>
2001-05-06 05:00 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-05-07 17:04 ` Bruce Momjian <pgman@candle.pha.pa.us>
2004-02-23 08:17 DATEADD Sumita Biswas <sbiswas@cisco.com>
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