pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUsing DateDiff with Postgres
3+ messages / 3 participants
[nested] [flat]
* Using DateDiff with Postgres
@ 2001-06-28 11:01 Jeff Rhys-Jones <jeff@emojo.com>
0 siblings, 2 replies; 3+ messages in thread
From: jeff@emojo.com @ 2001-06-28 11:01 UTC (permalink / raw)
To: pgsql-sql
Hi there. I was wondering if anyone can tell me the correct syntax for
using DateDiff for postgrees. I'm using MI (or mi) for minute and I
keep getting attribute 'mi' not found.
I've looked at postgres.org and can't seem to find any ref. to using
datediff.
Many thanks,
Jeff
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Using DateDiff with Postgres
@ 2001-06-28 14:44 Richard Huxton <dev@archonet.com>
parent: Jeff Rhys-Jones <jeff@emojo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Richard Huxton @ 2001-06-28 14:44 UTC (permalink / raw)
To: Jeff Rhys-Jones <jeff@emojo.com>; pgsql-sql
From: "Jeff Rhys-Jones" <jeff@emojo.com>
> Hi there. I was wondering if anyone can tell me the correct syntax for
> using DateDiff for postgrees. I'm using MI (or mi) for minute and I
> keep getting attribute 'mi' not found.
>
> I've looked at postgres.org and can't seem to find any ref. to using
> datediff.
You just subtract dates with PG:
select now() - CURRENT_DATE;
Will return an "interval" type with the elapsed time since midnight. If you
want that in seconds do:
select extract(epoch from (now() - CURRENT_DATE));
Converting to minutes is obviously easy from there.
I think datediff() is a MS-Access thing isn't it?
- Richard Huxton
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Using DateDiff with Postgres
@ 2001-06-28 17:15 Josh Berkus <josh@agliodbs.com>
parent: Jeff Rhys-Jones <jeff@emojo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Josh Berkus @ 2001-06-28 17:15 UTC (permalink / raw)
To: pgsql-sql
Bruce, Tom, Etc:
This question comes up so often. Can't we have a FAQ about it
somewhere?
Jeff,
> Hi there. I was wondering if anyone can tell me the correct syntax
> for
> using DateDiff for postgrees. I'm using MI (or mi) for minute and I
> keep getting attribute 'mi' not found.
Datediff is not a SQL function. It is a MICROSOFT function, due to MS's
poor implementation of data types.
In PostgreSQL, you simply add and subtract interval values to datetime
values:
'2001-06-27 14:43:21'::DATETIME - '00:10:00'::INTERVAL = '2001-06-27
14:33:21'::DATETIME
'2001-06-27 14:43:21'::DATETIME - '2001-06-27 14:33:21'::DATETIME =
'00:10:00'::INTERVAL
For more information, see "Functions and Operators" in the PostgreSQL
online docs.
-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] 3+ messages in thread
end of thread, other threads:[~2001-06-28 17:15 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-28 11:01 Using DateDiff with Postgres Jeff Rhys-Jones <jeff@emojo.com>
2001-06-28 14:44 ` Richard Huxton <dev@archonet.com>
2001-06-28 17:15 ` Josh Berkus <josh@agliodbs.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