Re: Help with date math

Поиск
Список
Период
Сортировка
От Reid Thompson
Тема Re: Help with date math
Дата
Msg-id 46A2954F.6090802@ateb.com
обсуждение исходный текст
Ответ на Help with date math  ("Chris Hoover" <revoohc@gmail.com>)
Список pgsql-general
Chris Hoover wrote:
> I need some help.  I am trying to replicate a function from Sybase
> ASA, and am having difficulty.
>
> I need to be able to subtract 2 date (or timestamps) and return the
> results expressed in days, weeks, month, quarters, or years.  How do I
> do this?
>
> I believe Postgres is returning the number of days when you subtract
> to days.
> i.e. postgres=# select current_date - '2007/01/01';
>  ?column?
> ----------
>       200
> (1 row)
>
>
>
> However, I can not figure out how to get the results expressed as 7
> months, or 2 quarters, x weeks, or 0 years.  I have tried to use
> date_part, but since the subtraction is returning an integer, it is
> not happy.
>
> Any help would be greatly appreciated.
>
> Chris
>
> P.S.
>
> I'm trying to replicate Sybase's datediff function.
postgres=# select date_part('month', age(current_date, '2007/01/01'));
 date_part
-----------
         6
(1 row)


В списке pgsql-general по дате отправления:

Предыдущее
От: Reid Thompson
Дата:
Сообщение: Re: Help with date math
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: help with tsearch2 stem compile