Thread: Days betwen dates

Days betwen dates

From
Andy Holman
Date:
Anyone know how I can just get the number of
days between dates in 2 columns in a query?

I am using something like age('dateone', 'now')
currently but that returns 1 year 10 mons 14 12:53:10
or something of the like. I just want the days between
them. I am using php. Please let me know if you have
any ideas.

Thanks,
Andy

Re: Days betwen dates

From
Andy Holman
Date:
Actually I found a fix for this (kinda)
There is a function named date_part. And
you can use something like

SELECT date_part('epoch', age('2001-01-24')) / 60 / 60 /24;

I believe that was what I used, and that gives you the days.
I am working from memory at the moment, but that is close.

--Andy

Stuart Urban wrote:
>
> I do not know if Postgres has the TO_DAYS() function, but I use that one
> in MySQL.  Try something like TO_DAYS(dateone) - TO_DAYS(now());  [don't
> know if the syntax is correct, but you can probably figure it out if you
> see whether the TO_DAYS() function exists].
>
> --Stu
>
> On Tue, 9 Jan 2001, Andy Holman
> wrote:
>
> > Anyone know how I can just get the number of
> > days between dates in 2 columns in a query?
> >
> > I am using something like age('dateone', 'now')
> > currently but that returns 1 year 10 mons 14 12:53:10
> > or something of the like. I just want the days between
> > them. I am using php. Please let me know if you have
> > any ideas.
> >
> > Thanks,
> > Andy
> >