Thread: function to find difference between in days between two dates

function to find difference between in days between two dates

From
"Ashish Karalkar"
Date:
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
 
 
 

Re: function to find difference between in days between two dates

From
"Pavel Stehule"
Date:
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
>
>
>

Re: function to find difference between in days between two dates

From
"A. Kretschmer"
Date:
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


Re: function to find difference between in days between two dates

From
"Pavel Stehule"
Date:
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


Re: [GENERAL] function to find difference between in days between two dates

From
"Pavel Stehule"
Date:
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

Re: [GENERAL] function to find difference between in days between two dates

From
"Pavel Stehule"
Date:
> 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