pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedfunction to find difference between in days between two dates
8+ messages / 4 participants
[nested] [flat]
* function to find difference between in days between two dates
@ 2007-06-14 06:26 Ashish Karalkar <ashish.karalkar@info-spectrum.com>
0 siblings, 2 replies; 8+ messages in thread
From: Ashish Karalkar @ 2007-06-14 06:26 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-sql
Hello all,
Is there any function to find differences in days between two dates?
I am using
select abs(current_date - '2007-06-15')
to get the desired result.
but I think there must be a function and I am missing it,
if so, can anybody please point me to that.
Thanks in advance
With regards
Ashish Karalkar
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] function to find difference between in days between two dates
@ 2007-06-14 07:00 Pavel Stehule <pavel.stehule@gmail.com>
parent: Ashish Karalkar <ashish.karalkar@info-spectrum.com>
1 sibling, 1 reply; 8+ messages in thread
From: Pavel Stehule @ 2007-06-14 07:00 UTC (permalink / raw)
To: Ashish Karalkar <ashish.karalkar@info-spectrum.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql
Hello
PostgreSQL hasn't any official function for it. If you need it, you
can write own function
CREATE FUNCTION date_diff(date, date) returns integer as $$
select $1-$2; $$ language sql;
Regards
Pavel Stehule
2007/6/14, Ashish Karalkar <ashish.karalkar@info-spectrum.com>:
>
>
> Hello all,
>
> Is there any function to find differences in days between two dates?
>
>
> I am using
>
> select abs(current_date - '2007-06-15')
>
> to get the desired result.
> but I think there must be a function and I am missing it,
> if so, can anybody please point me to that.
>
>
> Thanks in advance
>
> With regards
> Ashish Karalkar
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: function to find difference between in days between two dates
@ 2007-06-14 07:02 A. Kretschmer <andreas.kretschmer@schollglas.com>
parent: Ashish Karalkar <ashish.karalkar@info-spectrum.com>
1 sibling, 1 reply; 8+ messages in thread
From: A. Kretschmer @ 2007-06-14 07:02 UTC (permalink / raw)
To: pgsql-sql
am Thu, dem 14.06.2007, um 11:56:15 +0530 mailte Ashish Karalkar folgendes:
> Hello all,
>
> Is there any function to find differences in days between two dates?
Yes, age().
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: function to find difference between in days between two dates
@ 2007-06-14 07:39 Pavel Stehule <pavel.stehule@gmail.com>
parent: A. Kretschmer <andreas.kretschmer@schollglas.com>
0 siblings, 0 replies; 8+ messages in thread
From: Pavel Stehule @ 2007-06-14 07:39 UTC (permalink / raw)
To: A. Kretschmer <andreas.kretschmer@schollglas.com>; +Cc: pgsql-sql
2007/6/14, A. Kretschmer <andreas.kretschmer@schollglas.com>:
> am Thu, dem 14.06.2007, um 11:56:15 +0530 mailte Ashish Karalkar folgendes:
> > Hello all,
> >
> > Is there any function to find differences in days between two dates?
>
> Yes, age().
>
>
there is difference
date - date --> integer
age(date::timestamp, date::timestamp) --> interval
regards
Pavel
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] function to find difference between in days between two dates
@ 2007-06-14 11:14 Martijn van Oosterhout <kleptog@svana.org>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Martijn van Oosterhout @ 2007-06-14 11:14 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Ashish Karalkar <ashish.karalkar@info-spectrum.com>; pgsql-general@postgresql.org; pgsql-sql
On Thu, Jun 14, 2007 at 09:00:12AM +0200, Pavel Stehule wrote:
> Hello
>
> PostgreSQL hasn't any official function for it. If you need it, you
> can write own function
Not true. Anything that is done by an operator as actually done by a
function. So the function exists:
# \df date_mi
List of functions
Schema | Name | Result data type | Argument data types
------------+---------+------------------+---------------------
pg_catalog | date_mi | integer | date, date
(1 row)
You may have to dig through the pg_operator table to find it though.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] function to find difference between in days between two dates
@ 2007-06-14 11:54 Pavel Stehule <pavel.stehule@gmail.com>
parent: Martijn van Oosterhout <kleptog@svana.org>
0 siblings, 1 reply; 8+ messages in thread
From: Pavel Stehule @ 2007-06-14 11:54 UTC (permalink / raw)
To: Martijn van Oosterhout <kleptog@svana.org>; Pavel Stehule <pavel.stehule@gmail.com>; Ashish Karalkar <ashish.karalkar@info-spectrum.com>; pgsql-general@postgresql.org; pgsql-sql
2007/6/14, Martijn van Oosterhout <kleptog@svana.org>:
> On Thu, Jun 14, 2007 at 09:00:12AM +0200, Pavel Stehule wrote:
> > Hello
> >
> > PostgreSQL hasn't any official function for it. If you need it, you
> > can write own function
>
> Not true. Anything that is done by an operator as actually done by a
> function. So the function exists:
>
> # \df date_mi
> List of functions
I know about it, but it's undocumented
Pavel
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] function to find difference between in days between two dates
@ 2007-06-14 12:26 Martijn van Oosterhout <kleptog@svana.org>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Martijn van Oosterhout @ 2007-06-14 12:26 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Ashish Karalkar <ashish.karalkar@info-spectrum.com>; pgsql-general@postgresql.org; pgsql-sql
On Thu, Jun 14, 2007 at 01:54:09PM +0200, Pavel Stehule wrote:
> ># \df date_mi
>
> I know about it, but it's undocumented
Hrm, yet Bruce mentions it in one of his documents.
http://momjian.us/main/writings/pgsql/data_processing.pdf
It may be undocumented, but it get a lot of hits on google :)
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] function to find difference between in days between two dates
@ 2007-06-14 12:47 Pavel Stehule <pavel.stehule@gmail.com>
parent: Martijn van Oosterhout <kleptog@svana.org>
0 siblings, 0 replies; 8+ messages in thread
From: Pavel Stehule @ 2007-06-14 12:47 UTC (permalink / raw)
To: Martijn van Oosterhout <kleptog@svana.org>; Pavel Stehule <pavel.stehule@gmail.com>; Ashish Karalkar <ashish.karalkar@info-spectrum.com>; pgsql-general@postgresql.org; pgsql-sql
> Hrm, yet Bruce mentions it in one of his documents.
>
> http://momjian.us/main/writings/pgsql/data_processing.pdf
>
> It may be undocumented, but it get a lot of hits on google :)
>
why google? look to pgsql/src/backend/utils/adt/date.c :-)
Regards
Pavel Stehule
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2007-06-14 12:47 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-06-14 06:26 function to find difference between in days between two dates Ashish Karalkar <ashish.karalkar@info-spectrum.com>
2007-06-14 07:00 ` Pavel Stehule <pavel.stehule@gmail.com>
2007-06-14 11:14 ` Martijn van Oosterhout <kleptog@svana.org>
2007-06-14 11:54 ` Pavel Stehule <pavel.stehule@gmail.com>
2007-06-14 12:26 ` Martijn van Oosterhout <kleptog@svana.org>
2007-06-14 12:47 ` Pavel Stehule <pavel.stehule@gmail.com>
2007-06-14 07:02 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2007-06-14 07:39 ` Pavel Stehule <pavel.stehule@gmail.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